views:

45

answers:

1

Im using a LINQDataSource to populate a GridView of Universities.

Each University has an associated State, which is in another table and associated by a foreign key (StateID).

I have a TemplateField in the GridView so that when you view it normally it displays the StateName which comes from the State table and when you edit it shows a DDL populated with everything from the State table.

    <asp:TemplateField ConvertEmptyStringToNull="False" HeaderText="State" SortExpression="State">
          <EditItemTemplate>
             <asp:DropDownList ID="DropDownListStateEdit" runat="server"
             DataSourceID="LinqDataSourceStates" DataTextField="StateName" DataValueField="StateID"
             SelectedValue='<%#Eval("StateID") %>'>
             </asp:DropDownList>
          </EditItemTemplate>
          <ItemTemplate>
               <asp:Label ID="Label1" runat="server" Text='<%#Eval("State.StateName") %>'></asp:Label>
          </ItemTemplate>
    </asp:TemplateField>

If I debug, inside of RowUpdating, GridViewUpdateEventArgs.NewValues doesnt even have a key for State.

Question: How do I let my gridview know I want it to update this column? All the BoundFields just seem to work...

+1  A: 

In EditItemTemplate you should use #Bind("StateID") instead of #Eval("StateID").

Rover
Ah. Thanks, worked great. +1 +Answer =D
Blankasaurus