Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear sir

i have a two page in which i am using pagination.
in one page i have use record per page is 20 but other page record per page is 150 how to use it
so i am using session for recodperpage
for one page
VB
If Session("recordPerPage") = "150" Then
           RecordPerPage = "150"
       Else
           RecordPerPage = Application("RecordPerPage")
       End If

but hear problem is that when i use another page it does not blank Session("recordPerPage")
how to correct it..


thanks in advance
Posted

Solution in C# which you can understand and translate later...

Instead of Session, you can use a static variable like:
static int recordPerPage = 20;

Then, in Page_Load():
if(Request.QueryString["Page"]!=null)
{
   if(Request.QueryString["Page"].ToString()=="2")
       recordPerPage = 150;
}


Above mentioned is the main and correct solution for your problem according to me. Still, if you want to clear the Session variable, you can do it easily by:
Session["recordPerPage"] = "";

You have to do this as Session variables do not lose their values on another Page call / Load. This is their main property and that's why they are used. And if you want to clear their value, you have to clear it manually by assigning null or "" value to them.
 
Share this answer
 
v3
First of all, I am not sure why are using Session to store the Page length. It should be an application/page setting instead. On one page set it 20 and 150 on another, that it!
 
Share this answer
 
Comments
koolprasad2003 29-Jul-11 8:25am    
yep...my 4
There is no need to store record count in Session, you can directly get it by using GridView's object.
if you want to clear session value then you can use following code

Session("recordPerPage") = ""


In your code you have use the same veriable in Application object also, why so ?
 
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