Introduction:
In this article we will discuss different way
to get DataKeyNames from GridView
on RowEditing event. Suppose you have a GridView grdEmp
having DataKeyNames empid and you want to
read empid from DataKeyNames on Gridview’s RowEditing event then here is the code:
<asp:GridView
ID="grdEmp" runat="server" DataKeyNames="empid"
onrowediting="grdEmp_RowEditing" ></GridView>
C#.NET Code to get DataKeyNames from GridView on RowEditing event
of gridview
protected void grdEmp_ RowEditing (object sender, GridViewEditEventArgs e)
{
int empId = Convert.ToInt32(grdEmp.DataKeys[e.RowIndex].Value);
//First way to get value
int empId = Convert.ToInt32(grdEmp.DataKeys[e.RowIndex].Value.ToString());//Second
way to get value
int empId = Convert.ToInt32(grdEmp.DataKeys[e.RowIndex].Values["empid
"].ToString());//Third way to get value
}
VB.NET Code to get DataKeyNames from GridView on RowEditing event of gridview
'First way to get value
Dim empId As Integer = Convert.ToInt32(grdEmp.DataKeys(e.RowIndex).Value)
'Second way to get value
Dim empId As
Integer = Convert.ToInt32(grdEmp.DataKeys(e.RowIndex).Value.ToString())
'Third way
Dim empId As Integer
=Convert.ToInt32(grdEmp.DataKeys(e.RowIndex).Values("EMP_ID").ToString())
End Sub
0 comments:
Post a Comment