Here I have created sample that will help you out.
CS.aspx
<div>
<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</cc1:ToolkitScriptManager>
<asp:LinkButton ID="lnkDummy" runat="server"></asp:LinkButton>
<cc1:ModalPopupExtender ID="ModalPopupExtender1" BehaviorID="mpe" runat="server"
PopupControlID="pnlPopup" TargetControlID="lnkDummy" BackgroundCssClass="modalBackground"
CancelControlID="btnHide">
</cc1:ModalPopupExtender>
<asp:Panel ID="pnlPopup" runat="server" CssClass="modalPopup" Style="display: none">
<div class="header">
Modal Popup
</div>
<div class="body">
<asp:GridView ID="GridView1" runat="server" HeaderStyle-BackColor="green" AutoGenerateColumns="false"
Font-Names="Arial" OnPageIndexChanging="OnPaging" Font-Size="11pt" AlternatingRowStyle-BackColor="#C2D69B"
AllowPaging="true">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:RadioButton ID="RadioButton1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField ItemStyle-Width="150px" DataField="CustomerID" HeaderText="CustomerID" />
<asp:BoundField ItemStyle-Width="150px" DataField="City" HeaderText="City" />
<asp:BoundField ItemStyle-Width="150px" DataField="PostalCode" HeaderText="PostalCode" />
</Columns>
</asp:GridView>
<br />
<asp:Button ID="btnHide" runat="server" Text="Hide Modal Popup" />
<asp:Button ID="Button1" Text="Send" runat="server" OnClick="SendRowData" />
</div>
</asp:Panel>
<br />
</div>
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ModalPopupExtender1.Show();
GetSelectedRecord();
BindGrid();
Session["SelectedData"] = null;
}
}
private void BindGrid()
{
string strQuery = "SELECT TOP 10 CustomerID,City,PostalCode FROM CUSTOMERS";
DataTable dt = new DataTable();
String strConnString = System.Configuration.ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
SqlDataAdapter sda = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand(strQuery);
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
try
{
con.Open();
sda.SelectCommand = cmd;
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
sda.Dispose();
con.Dispose();
}
}
private void GetSelectedRecord()
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
RadioButton rb = (RadioButton)GridView1.Rows[i].Cells[0].FindControl("RadioButton1");
if (rb != null)
{
if (rb.Checked)
{
HiddenField hf = (HiddenField)GridView1.Rows[i].Cells[0].FindControl("HiddenField1");
if (hf != null)
{
ViewState["SelectedContact"] = hf.Value;
}
break;
}
}
}
}
private void SetSelectedRecord()
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
RadioButton rb = (RadioButton)GridView1.Rows[i].Cells[0].FindControl("RadioButton1");
if (rb != null)
{
HiddenField hf = (HiddenField)GridView1.Rows[i].Cells[0].FindControl("HiddenField1");
if (hf != null && ViewState["SelectedContact"] != null)
{
if (hf.Value.Equals(ViewState["SelectedContact"].ToString()))
{
rb.Checked = true;
break;
}
}
}
}
}
protected void OnPaging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
SetSelectedRecord();
}
protected void SendRowData(object sender, EventArgs e)
{
DataTable table = new DataTable();
GridViewRow headerRow = GridView1.HeaderRow;
foreach (TableCell item in headerRow.Cells)
{
DataColumn column = new DataColumn();
column.ColumnName = item.Text;
table.Columns.Add(column);
}
foreach (GridViewRow rows in GridView1.Rows)
{
if (((RadioButton)rows.FindControl("RadioButton1")).Checked)
{
DataRow row = table.NewRow();
int i = 0;
foreach (TableCell item in rows.Cells)
{
row[i] = item.Text;
i++;
}
table.Rows.Add(row);
}
}
Session["SelectedData"] = table;
Response.Redirect("~/Default.aspx");
}
Default.aspx
<div>
<asp:Button Text="Back" runat="server" OnClick="Back" />
</div>
Code
protected void Page_Load(object sender, EventArgs e)
{
if (Session["SelectedData"] != null)
{
DataTable selectedData = (DataTable)Session["SelectedData"];
HtmlTable table = new HtmlTable();
HtmlTableRow tableHeaderRow = new HtmlTableRow();
foreach (DataColumn item in selectedData.Columns)
{
HtmlTableCell cell = new HtmlTableCell();
cell.InnerHtml = item.ColumnName;
tableHeaderRow.Cells.Add(cell);
}
table.Rows.Add(tableHeaderRow);
foreach (DataRow rows in selectedData.Rows)
{
HtmlTableRow row = new HtmlTableRow();
foreach (var item in rows.ItemArray)
{
HtmlTableCell cell = new HtmlTableCell();
cell.InnerHtml = item.ToString();
row.Cells.Add(cell);
}
table.Rows.Add(row);
}
this.form1.Controls.Add(table);
}
}
protected void Back(object sender, EventArgs e)
{
Response.Redirect("~/CS.aspx");
}
Screenshot
