Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SelectedIndexChanged not firing...but not so simple

Status
Not open for further replies.

organicg

Programmer
Oct 21, 2002
151
US
I need a control event guru here.
I have a Dropdownlist to choose categories and a list of results from that category displayed on a page. By default the 1st category is selected and its results displayed. If you pick a diff. category the page posts back and the SelectedIndexChanged event handler gets new data and binds it to the repeater. Simple, no problems.
Here's the twist/problem: I also render links to page through the results within each category. The pager links have the id for the category and also the page, like:
Code:
<a href="/default.aspx?id=3&page=1
If I click through pages, I'm showing the correct page of results...each time making sure to set the .SelectedValue of the Dropdownlist to the category being viewed so the user continues to see that one selected in the DDL. However, the next time I change the category in the dropdownlist, SelectedIndexChanged does NOT fire and it shows page one of the result set that was being paged through prior to changing the category in the dropdownlist. I'll spare you any code and hope theoretical advice will help, for starters. I'm guessing I'm doing something in the wrong event handler, but I've tried 50 things and none are working.
 
When I select different categories in the dropdownlist, I can see that the .SelectedValue has the new value when Page_Load fires. However, when I follow the steps above(click to the next page of results via link, and then pick a new category in the ddl) I don't see the .SelectedValue get updated in the Page_Load to the posted back value.
 
.each time making sure to set the .SelectedValue of the Dropdownlist to the category being viewed so the user continues to see that one selected in the DDL.

Not sure if the is the cause of your issue, but, you should not have to set the selected value of the DDL on each postback. This is where the viewstate comes into play. If you find you HAVE to set it each time, then you are not binding correctly. You need to check if it is a postback:
Code:
   if (!Page.IsPostBack)
   { //get your data here...
     //bind data to repeater here ..
   }
If you don't place that code in an if block, you will fetch and rebind on each postback and therefore lose the selectedvalue that that user chose.

This is just a place to start since you posted no code.
 
I am only setting the .SelectedValue when it's NOT a postback, but they've used the hyperlink(not PostBack) pager so the DDL has the same category selected. That's why this is a tricky UI. I'm trying to code a UI with both GETs and POSTs
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top