开发者

Gridview: how to restore page position after user clicked

i have a gridview control on the page with 10 pages and in that gridview column i have a hyperlink where user can click the link and it will take to different page.

the mainpage.aspx with my gridview control on it:

<asp:GridView ID="gv" Width="100%" runat="server" AllowPaging="true"/>
<Columns>

 <asp:TemplateField ShowHeader="true"> 
  <ItemTemplate>
      <asp:Label ID="lblTitle" runat="server" Text='<%# Eval("Title") %>' />
           <asp:HyperLink id="hlView" runat="server">View Users</asp:HyperLink> 
 </ItemTemplate>
 ......................
 ......................
 .......................


public void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
  if (e.Row.RowType == DataContro开发者_运维知识库lRowType.DataRow)
  {
    HyperLink hl = e.Row.FindControl("hlView") as HyperLink;
    Customers t = e.Row.DataItem;
    hl.NavigateUrl = "User.aspx?Id=" + t.Id;
    ..................
    ......................

on my User.aspx page

i have

<a href="#" onclick="javascript:history.go(-1);return true;">Back To Page</a> 

my question is:

here is the scanrio i ran into and not sure how to resolve this.

let says, i am on page 7 on the mainpage.aspx and i click on the link and it will take me to user.aspx page and from the user.aspx when i click on the BAck to Page then it will take me to page but i will be landed on page 1 instead of page 7

how can i restore or maintain the page number and back to the same page where i come from?

is there a way to do that?


Session State is your friend. You can either store the result set into session along with the resultset page or you can just store the page in session and query the data.

I just cannot remember if you use page_int or preload event - one of them... It will work on page load....

As Wicked Coder said use Session["PrevPage"], fill it on page_loaded event, click event


How about you try

<a href="javascript:history.back();" target="_self">Go Back Page</a>

If nothing works out you can always create a Session["PrevPage"] and store the previous page name in that session and use it when you click back. But thats not the preferred way though.

EDIT: Using Session from aspx page.

<a href='<%=Session["PrevPage"]%>'>Back To Page</a> 
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜