trigger database update when dropdownlist item selected in gridview not in edit mode

I have a gridview that list some records.  In each row, I have a dropdownlist that is used to categorize the record. I want users to be able to select a dropdownlist item and then trigger some event so I can update that record in the database with that value.  I want to do this with out the user having to hit an edit button.   I am using Visual Studio 2008 and prefer a VB example, but C# will do as well.  Thanks.
hfp06Asked:
Who is Participating?
 
hfp06Connect With a Mentor Author Commented:
I found out what I have to do.  I have to add a event handler for the dropdownlist for the SelectedIndexChanged event during the grid view's RowCreated event.  Then do my updates from the SelectedIndexChanged event.  Thanks for your advice.
    Private Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim ddl As DropDownList = CType(e.Row.FindControl("DropDownList1"), DropDownList)
            ddl.AutoPostBack = True
            AddHandler ddl.SelectedIndexChanged, AddressOf dropDownList_SelectedIndexChanged
        End If
    End Sub

Open in new window

0
 
amar31282Connect With a Mentor Commented:
please set  the autopostback feature of the ddl to true and trigger the funtionality in the gridview's onrowcommand / onitemcommand (which ever applicable not sure for gridview) of the grid view
0
 
havj123Connect With a Mentor Commented:
As amar said, set Autopostback property of dropdown "TRUE". Then on gridviews OnRowCommand event find the dropdownlist control with FindControl method and do whatever you want.
0
 
hfp06Author Commented:
I set the autopostback property of the dropdown to TRUE but it does not seem to fire the gridview's RowCommand event.  I put an image button in the same column and if I click that it generates the RowCommand event but the dropdownlist does nothing except generate the post back that I can see.  
0
 
ZombieX6Commented:
Hi,
newbie to C#.  what would the C# code look like to accomplish this?
Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.