How run custom update code in gridview?

Posted on 2008-11-18
Last Modified: 2012-06-21
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?

Question by:RobertNZana
    1 Comment
    LVL 2

    Accepted Solution

    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


    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    746 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

    15 Experts available now in Live!

    Get 1:1 Help Now