Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all
I have a page that loads a lot of data , so I used paging in it.
if I change the index of that paging (like from the first page to the third page)
I reload the page with query string carry that value.
The problem here, there are some cases I use query string and some other no.
In the case I want query sring, there is an error

I tried that but there is an error

NameValueCollection n = Request.QueryString;
if (n.HasKeys())
{
    // Get first key and value
    string Current = n.Get(0);
    // Test different keys
    if (Current == "page")
    {
        if ((Request.QueryString["page"].ToString().Trim() != string.Empty))
        {
           CurrentPage = Convert.ToInt16(Request.QueryString["page"]);
           fill_Account();
        }


any help,
thanks

[edit]inline code converted to code block (It preserves the formatting), capitalization, removed spurious "iii" - OriginalGriff[/edit]
Posted
Updated 8-Feb-11 0:30am
v3
Comments
moon2011 8-Feb-11 6:28am    
thanks for your reply, but it still appears an exception
"Object reference not set to an instance of an object."
Umair Feroze 8-Feb-11 6:32am    
Please use the code provided in the answer. It is working fine.

1 solution

I believe the following code will work for you:

if (Request.QueryString["page"] != null && !String.IsNullOrEmpty(Request.QueryString["page"].ToString().Trim())){
    CurrentPage = Convert.ToInt16(Request.QueryString["page"]);
    fill_Account();
}

This will verify if you have the key Page in the query string and its value is not empty or null. If these conditions match it will proceed with the functionality you need.
 
Share this answer
 
v2

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