Refer this code:
Default.aspx
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
body
{
font-family: Arial;
font-size: 10pt;
}
</style>
<script type="text/javascript">
function PassValue() {
window.open("DetailsCS.aspx", "Popup", "width=300,height=400");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" HeaderStyle-BackColor="#3AC0F2" HeaderStyle-ForeColor="White"
RowStyle-BackColor="#A1DCF2" AlternatingRowStyle-BackColor="White" AlternatingRowStyle-ForeColor="#000"
runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" ItemStyle-Width="30" />
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblName" runat="server" Text='<%# Eval("Name") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Country" HeaderText="Country" ItemStyle-Width="150" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkDetails" runat="server" Text="Send Details" CommandArgument='<%# Eval("Id") %>'
OnClick="PassValues"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</form>
</body>
</html>
Default.aspx.cs:
Here i am calling a Script from code behind and storing the GridViewRow data in Sesssion.
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id"), new DataColumn("Name"), new DataColumn("Country") });
dt.Rows.Add(1, "John Hammond", "United States");
dt.Rows.Add(2, "Mudassar Khan", "India");
dt.Rows.Add(3, "Suzanne Mathews", "France");
dt.Rows.Add(4, "Robert Schidner", "Russia");
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
protected void PassValues(object sender, EventArgs e)
{
GridViewRow row = (sender as LinkButton).NamingContainer as GridViewRow;
Session["Row"] = row;
ClientScript.RegisterClientScriptBlock(this.GetType(), "show", "PassValue()", true);
}
DetailsCS.aspx
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
</script>
<style type="text/css">
body
{
font-family: Arial;
font-size: 10pt;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td>
<b>Id</b>
</td>
<td>
<asp:Label ID="lblId" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
<b>Name</b>
</td>
<td>
<asp:Label ID="lblName" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
<b>Country</b>
</td>
<td>
<asp:Label ID="lblCountry" runat="server"></asp:Label>
</td>
</tr>
</table>
</form>
</body>
</html>
DetailsCS.aspx.cs
I have change the code in the second page. I am reading the Row Details which is saved in Session.
protected void Page_Load(object sender, EventArgs e)
{
if (Session["Row"] != null)
{
GridViewRow row = (GridViewRow)Session["Row"];
lblId.Text = row.Cells[0].Text;
lblName.Text = (row.FindControl("lblName") as Label).Text;
lblCountry.Text = row.Cells[2].Text;
}
}
Thank You