Default.aspx
__________________________
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
onrowcommand="GridView1_RowCommand">
<Columns>
<asp:BoundField DataField="id" HeaderText="id" />
<asp:BoundField DataField="name" HeaderText="name" />
<asp:BoundField DataField="address" HeaderText="address" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="XXXXX" runat="server" Text="NEW PAGE" CommandName="AA" CommandArgument='<%#Eval("id") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Default.aspx.cs
_________________________________
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
BindGridview();
}
protected void BindGridview()
{
using (SqlConnection con = new SqlConnection("--------"))
{
con.Open();
SqlCommand cmd = new SqlCommand("Select * FROM TEST", con);
SqlDataReader dr = cmd.ExecuteReader();
GridView1.DataSource = dr;
GridView1.DataBind();
con.Close();
}
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "AA")
{
string id = e.CommandArgument.ToString();
Server.Transfer("Default2.aspx?id=" + id);
}
}
}
Default2.aspx.cs
_____________________________
protected void Page_Load(object sender, EventArgs e)
{
string id=Request.QueryString["id"];
}