Friday 30 May 2014

Get Gridview DataKeys value on RowDataBound and RowCommand gridview in asp.net

//***************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();
}

1 comment:

Excel Sort values in ascending order using function TEXTJOIN

 Excel ::  Text ::  1,3,5,2,9,5,11 Result :: 1,2,3,5,5,9,11 Formula ::     TEXTJOIN ( ",",1,SORT(MID(SUBSTITUTE( A1 ,","...