Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6238951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:18:22+00:00 2026-05-24T11:18:22+00:00

I have a GridView bound to some Entity Datasource. Editing is enabled. Entity shown

  • 0

I have a GridView bound to some Entity Datasource. Editing is enabled. Entity shown in GridView is associated with another entity. Let’s say I’m displaying Machines which are creating Products (none or one product type per machine). I’m displaying name of the product in gridview with

<ItemTemplate>
    <asp:Label ID="Label1" runat="server" 
        Text='<%# ((Machine)Container.DataItem).Product == null ? "-" : ((Machine)Container.DataItem).Product.Name %>'>
    </asp:Label>
</ItemTemplate>

which works well. Now I want to be able to edit associated product in EditItemTemplate. So I added

<EditItemTemplate>
    <asp:DropDownList runat="server" ID="ddProducts" DataSourceID="dsProducts" 
            DataTextField="Name" DataValueField="ProductID" 
            SelectedValue='<%#  Bind("Product.ProductID") %>'
            AppendDataBoundItems="true">
            <asp:ListItem Text="" Value="0"></asp:ListItem>
    </asp:DropDownList>
</EditItemTemplate>

It’s not working because when machine doesn’t have a product associated there is no matching SelectedValue and anyway Product is null. I added empty item to DropDownList which should be selected when machine has no product. And also if I edit machine with product and choose this item, column should be nulled.

How can I achieve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T11:18:24+00:00Added an answer on May 24, 2026 at 11:18 am

    I got it to work now. GridView automatically converts nulls to empty strings, so the problem was not with binding but with the special item I added for null values.

    Changing

    <asp:ListItem Text="" Value="0"></asp:ListItem>
    

    to

    <asp:ListItem Text="" Value=""></asp:ListItem>
    

    solved the problem instantly…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a GridView bound to an DataSource query with parameters tied to form
I have a gridview that is bound to a datasource on a Windows Form
I have a gridview that is bound to a datasource (Windows Forms, VB.NET). One
i have a GridView bound to a DataView. Some columns in the DataView's table
I have GridView bound to some List. In layout I created following template field:
I have a gridview bound to a sql server datasource. I am currently moving
I have a GridView that is bound to an Entity Framework object. I want
I have bound fields in GridView to some dateTime property of data objects. The
I have a GridView which is bound to a datasource, which occasionally has a
I have a GridView bound to an ICollection<UserAnswer> that needs to show two columns:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.