Click here to Skip to main content
15,887,386 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi all ,
i have a grid view , some button called "order by price", "order by date", ...
when i search an item in my grid view with these button, it works but only in the first page.
when i switch, for example, in the second page, the grid view lost the filter search .
So i want save my grid view in a session, probably will fix this problem.

What I have tried:

My GridView :

<pre>        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            Font-Names = "Arial" Caption = "Catalogo" 
            DataKeyNames="ID" DataSourceID="SqlDataSource1" AllowPaging="True"
            BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" 
            CellPadding="4" CellSpacing="2" ForeColor="Black" Height="100%" 
            Width="100%" AllowSorting="True"
            PageSize="50">
            <Columns>



Implementing Session :

<pre>Session("GridView1") = GridView1
Posted
Updated 5-May-17 6:01am
Comments
F-ES Sitecore 5-May-17 5:41am    
It won't solve your problem and is actually quite a bad idea. Instead google "asp.net gridview paging" and you'll find lots of articles that show you how to do this. Compare what they are doing with what you are doing to work out where you're going wrong.
EmanuelPirovano 5-May-17 6:24am    
Why it doesn't repair the problem ? Can u explain me ?
Yeah, i've already search on google my problem, i use a lots of google while i develop, but i find few results.

Thanks
ZurdoDev 5-May-17 9:09am    
Because storing a gridview in your session will take up a ton of resources and is a bad fix for an easy problem to solve. Paging is done all the time. We can't help you anymore than that because we can't see your code, but do as F-ES suggested and go through some samples online and you'll see what is different.
Bryian Tan 5-May-17 14:27pm    
Can you repopulate those filter criteria on postback? or save those filters criteria in session instead of the whole GridView.

1 solution

Hi,

It seems like the pageindex is not being set before databind.

try setting the pageindex in gridview_databinding event similar to databound.

and call databind method there if necessary.

also try setting the pageindex of the gridview from the session on first pageload.
 
Share this answer
 

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