Click here to Skip to main content
15,895,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a GridView on ASP.NET web form which I have bound to a data source and set it to have 10 records per page.

I also have a hyper link column on the GridView, such that a user can navigate to another page (details page) 
from the list. On the details page, they have "Back" button to return to the GridView page


I tried the below code but its not working
  
     <pre lang="c#">protected void GridViewIndexChanging(object sender, GridViewPageEventArgs e)
    {
        myGridView.PageIndex = e.NewPageIndex;
        Session["pageNumber"] = e.NewPageIndex;
    }
        if (!IsPostBack)
        {
            if (Session["pageNumber"] != null)
            {
                GridViewIndexChanged(myGridView, new GridViewPageEventArgs((int)Session["pageNumber"]));
            }
        }


What I have tried:

I tried the above code but its not working
Posted
Updated 30-Jan-18 23:21pm

1 solution

In place of link button you need to use Hyperlink and pass the id in query string.Then from that query string parameter you can load details page.If you don't want a separate database hit then put the complete object in a session and reuse the session after the redirection.

link button using in gridview another page redirect how? - DotNetFunda.com[^]

N.B:If you are sending the id by query string make sure you use encryption and decryption of query string parameters.
 
Share this answer
 
v2
Comments
Member 12324523 31-Jan-18 6:07am    
my question is different and the anwser you shared is different
[no name] 31-Jan-18 6:13am    
What do you need.Do you need to write me complete source code for the functionality?The solution provided above can give you an idea how to navigate to a page from link button click inside grid view.You have to only design your details page with a back button.On click of back button response.redirect to the page where your grid view is present.
Member 12324523 31-Jan-18 7:32am    
Every thing is done only thing which was left is suppose if ui have 15 pages in gridview and when i am in 10th page of gridview if i click a row in gridview of that 10th page i will be redirected to another page where i have a back button in that page and again if i click that back button i need to come to previous page which is working but i am going to first page in paging of gridview instead i need to go to 10th page on clicking back button

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