//***************Data Key Name
<asp:GridView ID="GVAgriclutureCrop" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="ID,Name " GridLines="None" OnRowCommand="GVAgriclutureCrop_RowCommand" OnRowDataBound="GVAgriclutureCrop_RowDataBound" PageSize="5" ShowFooter="True">
</asp:GridView>
//************** On RowDataBound
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string id= GridView1.DataKeys[e.Row.RowIndex]["ID"].ToString();
string name= GridView1.DataKeys[e.Row.RowIndex]["Name"].ToString();
}
}
//************** On RowCommand
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridViewRow gvr = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
int rnd = gvr.RowIndex;
string catid = GridView1.DataKeys[rnd]["ID"].ToString();
string crid = GridView1.DataKeys[rnd]["Name"].ToString();
}
<asp:GridView ID="GVAgriclutureCrop" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="ID,Name " GridLines="None" OnRowCommand="GVAgriclutureCrop_RowCommand" OnRowDataBound="GVAgriclutureCrop_RowDataBound" PageSize="5" ShowFooter="True">
</asp:GridView>
//************** On RowDataBound
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string id= GridView1.DataKeys[e.Row.RowIndex]["ID"].ToString();
string name= GridView1.DataKeys[e.Row.RowIndex]["Name"].ToString();
}
}
//************** On RowCommand
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridViewRow gvr = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
int rnd = gvr.RowIndex;
string catid = GridView1.DataKeys[rnd]["ID"].ToString();
string crid = GridView1.DataKeys[rnd]["Name"].ToString();
}
good
ReplyDelete