Note that there are some explanatory texts on larger screens.

plurals
  1. POGrid View Button Passing Data Via On Click
    primarykey
    data
    text
    <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>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload