GridView - Selected row data using datakey name | Asp.Net c#


GridView - Dynamic Select Button  | Asp.Net c#


Home.aspx

asp:GridView runat="server" ID="GrdLandDetails" CssClass="table table-striped table-bordered table-hover gridasp" PageSize="10" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="id,age"  AutoGenerateSelectButton="true" OnSelectedIndexChanging="GrdLandDetails_SelectedIndexChanging"
                                             
  Columns
                                                    asp:BoundField HeaderText="Name" DataField="Sname"
                                                    asp:BoundField HeaderText="Amount" DataField="amt"
                                                    asp:


Home.aspx.cs  | Code Behind

  protected void gv_bindowners_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
  {
         string Fname = gv_bindowners.DataKeys[e.NewSelectedIndex].Values["Sname"].toString;
         string Age = gv_bindowners.DataKeys[e.NewSelectedIndex].Values["age"].toString;
         string Amount = gv_bindowners.DataKeys[e.NewSelectedIndex].Values["amt"].toString;
  }




                                             

Social Media