title: Grid View Button Passing Data Via On Click
body: <p>I'm pretty new to C# and asp.net so apologies if this is a really stupid question.</p>
  
  <p>I'm using a grid view to display a number of records from a database. </p>
  
  <p>Each row has an Edit Button. When the button is clicked I want an ID to be passed back to a function in my .cs file. How do I bind the rowID to the Button field?</p>
  
  <p>I've tired using a hyper link instead but this doesn't seem to work because I'm posting back to the same page which already has a Permanter on the URL.</p>
  
  <p>asp.net </p>
  
  <pre><code>&lt;asp:GridView ID="gvAddresses" runat="server" onrowcommand="Edit_Row"&gt;
      &lt;Columns&gt;
          &lt;asp:ButtonField runat="server" ButtonType="Button" Text="Edit"&gt;
      &lt;/Columns&gt;
  &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>c#</p>
  
  <pre><code>        int ImplantID = Convert.ToInt32(Request.QueryString["ImplantID"]);
          Session.Add("ImplantID", ImplantID);
  
          List&lt;GetImplantDetails&gt; DataObject = ImplantDetails(ImplantID);
  
          System.Data.DataSet DSImplant = new DataSet();
          System.Data.DataTable DTImplant = new DataTable("Implant");
  
          DSImplant.Tables.Add(DTImplant);
  
          DataColumn ColPostCode = new DataColumn();
          ColPostCode.ColumnName = "PostCode";
          ColPostCode.DataType = typeof(string);
          DTImplant.Columns.Add(ColPostCode);
  
          DataColumn ColConsigneeName = new DataColumn();
          ColConsigneeName.ColumnName = "Consignee Name";
          ColConsigneeName.DataType = typeof(string);
          DTImplant.Columns.Add(ColConsigneeName);
  
          DataColumn ColIsPrimaryAddress = new DataColumn();
          ColIsPrimaryAddress.ColumnName = "Primary";
          ColIsPrimaryAddress.DataType = typeof(int);
          DTImplant.Columns.Add(ColIsPrimaryAddress);
  
          DataColumn ColImplantCustomerDetailsID = new DataColumn();
          ColImplantCustomerDetailsID.ColumnName = "Implant ID";
          ColImplantCustomerDetailsID.DataType = typeof(int);
          DTImplant.Columns.Add(ColImplantCustomerDetailsID); 
  
          foreach (GetImplantDetails Object in DataObject)
          {
  
              DataRow DRImplant = DTImplant.NewRow();
              DRImplant["PostCode"] = Object.GetPostCode();
              DRImplant["Consignee Name"] = Object.GetConsigneeName();
              DRImplant["Primary"] = Object.GetIsPrimaryAddress();
              DRImplant["Implant ID"] = Object.GeTImplantCustomerDetailsID();
              DTImplant.Rows.Add(DRImplant); &lt;--- this is what I need to be added to the button
  
          }
  
          gvAddresses.DataSource = DTImplant;
          gvAddresses.DataBind(); 
  </code></pre>