Update gridview with a button outside of the gridview

Posted on 2008-11-07
Last Modified: 2012-05-05
I have a gridview control where one of the columns contains a drop-down list box control.  Outside of the gridview I have an Update button.  I would like the OnClick event of the Update button to trigger an update but only for the rows where the drop-down value was changed.

Attached is my OnClick function so far.  I know how to step through the rows in the gridview, I'm just not sure how to do my comparison.


Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click


         For Each gv As GridViewRow In grdSearch.Rows

            Dim ddlSelectedValue As DropDownList = CType(gv.FindControl("ddlAssignedTo"), DropDownList)

            If ddlSelectedValue.SelectedValue <> Compare to What??? Then

               'code to perform update here

            End If


      Catch ex As Exception

      End Try

   End Sub

Open in new window

Question by:jbulldoza
    LVL 37

    Accepted Solution

    I imagine your dropdownlist is in a template column....
    The quick way to do this would be to put a hidden field in the same template column and give it a value the same as the value of the dropdownlist...then your comparison would be:
             For Each gv As GridViewRow In grdSearch.Rows
                Dim ddlSelectedValue As DropDownList = CType(gv.FindControl("ddlAssignedTo"), DropDownList)
     Dim hf as HiddenField = CType(gv.FindControl("hfAssignedTo"), HiddenField)
                If ddlSelectedValue.SelectedValue <> hf.Value Then
                   'code to perform update here
                End If

    Open in new window


    Author Comment

    Now it seems that ddlSelectedValue.SelectedValue is not updating.  It was working before, not sure what I changed.  Even if I change the item in the drop-down and then click Update - the SelectedValue does not change when I step through the For loop.

    Do I need to re-bind the grid and update my Update Panel?


    Author Closing Comment

    Hidden field, brilliant.  Thx.
    LVL 37

    Expert Comment

    Make sure you are not re-binding the dropdownlist on postback/callback

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    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…

    761 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

    7 Experts available now in Live!

    Get 1:1 Help Now