Grid View Button Passing Data Via On Click
Posted
by flyersun
on Stack Overflow
See other posts from Stack Overflow
or by flyersun
Published on 2010-06-16T12:37:40Z
Indexed on
2010/06/16
13:12 UTC
Read the original article
Hit count: 186
Hi, I'm pretty new to C# and asp.net so aplogies if this is a really stupid question.
I'm using a grid view to display a number of records from a database.
Each row has an Edit Button. When the button is clicked I want an ID to be passed back to a funtion in my .cs file. How do I bind the rowID to the Button field?
I've tired using a hyper link instead but this doens't seem to work because I'm posting back to the same page which already has a Permanter on the URL.
asp.net
<asp:GridView ID="gvAddresses" runat="server" onrowcommand="Edit_Row">
<Columns>
<asp:ButtonField runat="server" ButtonType="Button" Text="Edit">
</Columns>
</asp:GridView>
c#
int ImplantID = Convert.ToInt32(Request.QueryString["ImplantID"]);
Session.Add("ImplantID", ImplantID);
List<GetImplantDetails> 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); <--- this is what I need to be added to the button
}
gvAddresses.DataSource = DTImplant;
gvAddresses.DataBind();
© Stack Overflow or respective owner