开发者

Rebind same gridview again

I have ASP.NET page, Page1 and there is a gridview. There is also a linkbutton which takes user to Page2. And, once user clicks a button on Page2, the page is redirecting to Page1.

I want to rebind the gridview on the Page1 with previous gridview again upon coming back from Page2. So I am passing the gridview in the Session variables, and bin开发者_开发问答d it to same gridview again, but it looks like it's not binding (No gridview displayed).

Is there any way I could preserve the gridview and rebind it upon coming back from another page?

Thanks!


to put GridView in Session variable is not a good idea because it take lot memory ant time to convert it into string because every thing in Session variable is stored as a string.

So you can store DataTable or List (DataSource) in session and based on it you can call BindGrid function again like this.

In Page1.Aspx

void Page_Load() { If(!string.IsNullOrEmpty(Session["dataSource"])) { gridVies.DataSource = (DataTable)Session["dataSource"]; gridView.DataBind(); } else { BindGrid(); } } void HyperLinkClicked(sender s, EventArg e) { session["dataSource"] = gridView.DataSource; Response.Redirect("`\Page2.aspx"); }

In Page2.Aspx

Void Button_Clicked(Sender s,EventArg e) { Response.Redirect("`\Page1.aspx"); }


If you just want to rebind it then call the binding logic from your Page_Load handler.


If you want to persist the GridView you have to persist its datasource f.e. a DataTable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜