Click here to Skip to main content
15,914,500 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a session gridview and a session datatable. I want to display the session gridview on pageload itself. No error or exception is thrown. But I am unable to see the gridview.
Here is my code:

VB
<asp:GridView ID="grv" runat="server"
               ShowFooter="True" AutoGenerateColumns="False"
               CellPadding="4" ForeColor="#333333"
               GridLines="None" >

C#
protected void Page_Load(object sender, EventArgs e)
  {
DataTable tb = new DataTable();
        tb = (DataTable)Session["ss"];
        GridView gv = new GridView();
        grv = (GridView)Session["gv"];
        grv.DataSource = tb;
        grv.DataBind();
        grv.Visible = true;
   }

The Datatable 'tb' however has rows.
Posted
Updated 27-Nov-13 23:53pm
v2
Comments
Thanks7872 28-Nov-13 6:02am    
What is Session GridView and Session DataTable?
S.Rajendran from Coimbatore 28-Nov-13 6:24am    
I have a GV and Datatable in Page1. I use responce redirect to page2 and at the same time I want to retain the same status of both those controls with values. So I wanted to use this session method to bring to page2 and use them.

First create the session, suppose for the first request you can check 'Page.IsPostBack' property and for session check if(session["ss"] !=null)

protected void Page_Load(object sender, EventArgs e)
{
if(Page.Ispostback)
{
if(session["ss"]!=null && session["gv"]!=null)
{
DataTable tb = new DataTable();
tb = (DataTable)Session["ss"];
GridView gv = new GridView();
grv = (GridView)Session["gv"];
grv.DataSource = tb;
grv.DataBind();
grv.Visible = true;
}
else
Response.write("session is null");
}
 
Share this answer
 
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!!!
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900