After struggling an hour i got the solution I took two pages. below is mine firstPage code behind code.
protected void Page_LoadComplete(object sender, EventArgs e)
{
if (!IsPostBack)
CreateSession();
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("TestAnything.aspx");
}
private void CreateSession()
{
DataTable tb = GetTable();
GridView gv = new GridView();
gv.ID = "MyGrid";
gv.AutoGenerateColumns = true;
Session["DataTableSession"] = tb;
Session["MyGridinSession"] = gv;
}
And On My secondpage i.e. TestAnything.aspx I put the following code
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
AddGrid();
}
private void AddGrid()
{
GridView gv=(GridView) Session["MyGridinSession"];
DataTable tb=(DataTable) Session["DataTableSession"];
form1.Controls.Add(gv);
gv.DataSource = tb;
gv.DataBind();
}
in Whole Of the code trick is in bolded text of second page that you need to add your grid control to form container....
Hope This Helps!!!