
Untitled
By: a guest on
Apr 24th, 2012 | syntax:
None | size: 1.46 KB | hits: 11 | expires: Never
How to select a row from grid view and edit the details in a new webform using ASP.NET
<asp:HyperLinkField Text="View Details" DataNavigateUrlFields="YourId" DataNavigateUrlFormatString="details.aspx?id={0}" />
if(Request.QueryString["id"])!=null)
{
// Fetch respective item from database here & populate form fields
// Open connection(); execute datareader;populate form fields
}
<asp:GridView ID="GV_YourGridView" runat="server" OnRowDataBound="gdView_RowDataBound" >
</asp:GridView>
gdView.RowDataBound += new GridViewRowEventHandler(gdView_RowDataBound);
protected void gdView_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
string value = e.Row.Cells[0].Text; //gets your Primary Key from cell on Databind
e.Row.Cells[0].Controls.Clear(); //Clears existing controls. (not necessary)
e.Row.Cells[0].Text = "";//Clears the innertext of the cell
LinkButton LB = new LinkButton();//creates link button
LB.Text = value;//names it with your primarykey
LB.Attributes.Add("href", "view-edit.aspx?id=" + LB.Text);// links it to your edit page aswell as passing the primary key
LB.Attributes.Add("target", "_blank");//this makes your edit window open on new tab
e.Row.Cells[0].Controls.Add(LB);
}
catch { }
}
if(Request.QueryString["id"])!=null)
{
string ID = Request.QueryString["id"];
}