5 February 2014

Get DataKeyValues in RowDatabound

Generally we set the primary key values to the datakeyName property in gridview control and below code will help to get that date key values associated with a row in rowdatabound event.

protected void gv1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string userID = gv1.DataKeys[e.Row.RowIndex].Values[0].ToString();
            }
        }

No comments:

Post a Comment