如何使会话Gridview可见 [英] How to make a session Gridview to make visible
本文介绍了如何使会话Gridview可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个会话gridview和一个session数据表。我想在pageload本身上显示会话gridview。不会抛出任何错误或异常。但我无法看到gridview。
这是我的代码:
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:
<asp:GridView ID="grv" runat="server"
ShowFooter="True" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333"
GridLines="None" >
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;
}
数据表'tb'但是有行。
The Datatable 'tb' however has rows.
推荐答案
首先创建会话,假设第一个请求你可以检查'Page.IsPostBack'属性和会话检查if(session [ss]!= null)
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");
}
经过一个小时的努力,我得到了解决方案,我拿了两页。下面是我的第一页代码背后代码。
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;
}
和我的第二页即TestAnything.aspx我输入以下代码< br $>
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!!!
这篇关于如何使会话Gridview可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文