0

I want to mark checkboxlist item selected if it's value found in QueryString. e.g.

www.abcd.com/pproducts.aspx?price=1001-2000|2001-5000|5001-10000.

In this url I am filtering products with 3 different price range. Now I have checkboxlist which contains this prices like below

1001-2000

2001-5000

5001-10000

above-10000

so now I want to it should get selected 1001-2000, 2001-5000, 5001-10000

From below code I am redirecting page & making url

private void priceRange_SelectedIndexChanged(object sender, EventArgs e)
{
    string selectedPriceRange = priceRange.SelectedValue.ToString;
    foreach (ListItem chk in priceRange.Items) {
        if (selectedPriceRange.Contains(chk.Value)) {
            chk.Selected = true;
        }
    }

    Response.Redirect((Request.Url.AbsoluteUri) + "?price=" + selectedPriceRange);
}
2
  • what is the issue you are having? Commented Jun 7, 2017 at 9:20
  • @John I don't understand how to check items which are present in querystring value. Commented Jun 7, 2017 at 9:25

1 Answer 1

1
string price = Request.QueryString["price"];                           
string[] priceList = price.Split('|');                                  
foreach (string p in priceList)                                               
{                                                                            
    if (chkList.Items.FindByText(p) != null)                                  
    {                                      
          chkList.Items.FindByText(p).Selected = true;                        
    }                                                                           
}                                                                       

Above code will select each checkbox as per the value passed in query sting.

Sign up to request clarification or add additional context in comments.

1 Comment

Hence this is right solution but there are some drawback of this. Can you please solve my this issue. As per querystring checkbox item gets selected perfectly but suppose If I uncheck particular item from it then it doesn't get uncheck becuase pageLoad event executed first & while loading it gets that querystring again from url & item get selected again. How to escape from this? Seethis link i have posted question here stackoverflow.com/questions/44416897/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.