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

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

0
jbulldoza
Asked:
jbulldoza
  • 2
  • 2
1 Solution
 
samtran0331Commented:
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
         Next

Open in new window

0
 
jbulldozaAuthor Commented:
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()
0
 
jbulldozaAuthor Commented:
Hidden field, brilliant.  Thx.
0
 
samtran0331Commented:
Make sure you are not re-binding the dropdownlist on postback/callback
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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