Introduction:
In this article we will learn how to read
DataKeyNames on GridView's RowUpdating Event in asp.net.Suppose you have a GridView grdEmp having DataKeyNames DataKeynames empid and you want to read empid from DataKeyNames on
Gridview’s RowUpdating Event then here is the code:
Note: We are assuming empid is the primary key of the Employee table
Note: We are assuming empid is the primary key of the Employee table
<asp:GridView
ID="grdEmp" runat="server" DataKeyNames=" empid " onrowupdating="grdEmp_RowUpdating">
</GridView>
C#.Net Code to read DataKeyNames on GridView's
RowUpdating Event in asp.net
protected void grdEmp_RowUpdating(object sender, GridViewUpdateEventArgs e)
protected void grdEmp_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int empId = Convert.ToInt32(grdEmp.DataKeys[e.RowIndex].Value);
//First way
int empId = Convert.ToInt32(grdEmp.DataKeys[e.RowIndex].Value.ToString());//Second
way
int empId = Convert.ToInt32(grdEmp.DataKeys[e.RowIndex].Values["empid "].ToString());//Third
way
}
VB.Net Code to read
DataKeyNames on GridView's RowUpdating Event in asp.net
Protected Sub grdEmp_RowUpdating(sender As Object, e As GridViewUpdateEventArgs)
Protected Sub grdEmp_RowUpdating(sender As Object, e As GridViewUpdateEventArgs)
Dim empId As Integer = Convert.ToInt32(grdEmp.DataKeys(e.RowIndex).Value)
'First way
Dim empId As Integer = Convert.ToInt32(grdEmp.DataKeys(e.RowIndex).Value.ToString())
'Second way
Dim empId As Integer =Convert.ToInt32(grdEmp.DataKeys(e.RowIndex).Values("empid ").ToString())
'Third way
End Sub
0 comments:
Post a Comment