• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 537
  • Last Modified:

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.
0
hfp06
Asked:
hfp06
3 Solutions
 
amar31282Commented:
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
 
havj123Commented:
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
 
hfp06Author 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
 
ZombieX6Commented:
Hi,
newbie to C#.  what would the C# code look like to accomplish this?
Thanks.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now