Link to home
Start Free TrialLog in
Avatar of jbulldoza
jbulldoza

asked on

Update gridview with a button outside of the gridview

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.

Thanks.

   
Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
      Try
 
         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
         Next
 
      Catch ex As Exception
 
      End Try
 
   End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of samtran0331
samtran0331
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jbulldoza
jbulldoza

ASKER

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?

grdSearch.DataBind()
UpdatePanelGrid.Update()
Hidden field, brilliant.  Thx.
Make sure you are not re-binding the dropdownlist on postback/callback