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

Posted on 2009-04-17
Last Modified: 2012-05-06
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.
Question by:hfp06
    LVL 14

    Assisted Solution

    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
    LVL 6

    Assisted Solution

    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.

    Author Comment

    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.  

    Accepted Solution

    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


    Expert Comment

    newbie to C#.  what would the C# code look like to accomplish this?

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    This video discusses moving either the default database or any database to a new volume.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now