How run custom update code in gridview?

I have a gridview with several fields.  The user should be able to click 'edit', update several fields, then click 'update'.  I want to run CUSTOM code for the update command.  

How can I do this?  I suppose I would check the e.commandname in the rowcommand event, but I don't know how to access the controls that contains the new values.

Any code samples?

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.

Howdy Robert.

Try using the rowUpdating event of the gridview.  Use 'e.rowindex' and the findcontrol method to access the controls. See snippet below. I hope it helps!

Protected Sub grdMyPicks_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles grdMyPicks.RowUpdating
        If Page.IsValid Then
            Dim winner As String = CType(grdMyPicks.Rows(e.RowIndex).FindControl("ddlEditwinner"), DropDownList).SelectedValue
            SqlDataSource1.UpdateParameters("W_Team").DefaultValue = winner
        End If
    End Sub

Open in new window

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

From novice to tech pro — start learning today.