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

jbulldozaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.