View Single Post
  #1 (permalink)  
Old March 12th, 2009, 02:20 AM
RushNP774 RushNP774 is offline
Authorized User
 
Join Date: Mar 2009
Posts: 23
Thanks: 2
Thanked 0 Times in 0 Posts
Question Using a dropdown box in a GridView - How do I update the record with the dd's value?

I have a GridView control that gets its data correctly from a table (called Activity) with three columns:
  • Id - Automatically generated primary key
  • Name - Name of the activity
  • Category - Category of the activity
The [Category] field is populated by a dropdown list box that gets the categories from another table (and it works fine). When I update a record, I can change the [Name] of the activity (because it's a default textbox generated by the GridView), and the record is updated fine. But the value of the ddl box is not inserted into the record.

I'm pretty sure I need to change my UpdateCommand of the sqlDataSource that feeds my GridView, and/or add code to my dropdown box's but I'm at a loss of how to do that. Here is the template field of my GridView:

Code:
<EditItemTemplate>
    <asp:DropDownList ID="DropDownList1" 
        runat="server" AutoPostBack="False" DataSourceID="SqlDataSource3" 
        DataTextField="Name" DataValueField="Name">
    </asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
    <asp:Label ID="Label1" runat="server" Text='<%# Bind("Category") %>'></asp:Label>
</ItemTemplate>
And the UpdateCommand of my data source:

Code:
"UPDATE [Activity] SET [Name] = @Name, [Category] = @Category WHERE [Id] = @original_Id 
AND [Name] = @original_Name AND (([Category] = @original_Category) OR ([Category] IS NULL AND
 @original_Category IS NULL))"
I've seen similar questions asked many times, but can't seem to find one that's exactly my problem. If you know of an article or forum post that would help me out, I'd love to see it. Thanks in advance!

Last edited by RushNP774; March 12th, 2009 at 03:04 PM.. Reason: Broke the SQL command up in different lines