Hi leo08,
I have created a sample please refer this.
HTML
Default.aspx
<div>
<asp:GridView ID="GridView1" runat="server" HeaderStyle-BackColor="green" AutoGenerateColumns="false"
Font-Names="Arial" Font-Size="11pt" AlternatingRowStyle-BackColor="#C2D69B" AllowPaging="true">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:RadioButton ID="RadioButton1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ID" HeaderText="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Country" HeaderText="Country" />
</Columns>
</asp:GridView>
<asp:Button ID="btngetdetails" Text="Get Selected Row" runat="server" OnClick="GetSelectedRows" />
</div>
Default2.aspx
<div>
<asp:Button ID="Button1" Text="Back" runat="server" OnClick="Back" />
</div>
Code
Default.aspx
protected void Page_Load(object sender, EventArgs e)
{
if (!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 GetSelectedRows(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("ID"), new DataColumn("Name"), new DataColumn("Country") });
foreach (GridViewRow row in GridView1.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
RadioButton rb = (RadioButton)row.Cells[0].FindControl("RadioButton1");
if (rb.Checked)
{
int id = int.Parse(row.Cells[1].Text);
string name = row.Cells[2].Text;
string country = row.Cells[3].Text;
dt.Rows.Add(id, name, country);
}
}
}
Session["SelectedData"] = dt;
Response.Redirect("~/Default2.aspx");
}
Default2.aspx
protected void Page_Load(object sender, EventArgs e)
{
if (Session["SelectedData"] != null)
{
GridView gv = new GridView();
gv.AutoGenerateColumns = true;
gv.HeaderStyle.BackColor = Color.Green;
gv.AlternatingRowStyle.BackColor = Color.LightGreen;
gv.DataSource = Session["SelectedData"];
gv.DataBind();
form1.Controls.Add(gv);
}
}
protected void Back(object sender, EventArgs e)
{
Response.Redirect("~/Default.aspx");
}
Screenshot