开发者

Setting SelectedValue of a DropDownList on PageLoad

I have a bit of a problem with a DropDownList I am using. When the user changes the SelectedIndex, they get redirec开发者_C百科ted to the same page, but with a query string on the end based on their selected value.

Because I'm not posting, and redirecting instead, the state of the dropdownbox is not saved, so it always defaults to the first one.

But, if I save it in say a session, or set the selectedvalue according to the query string in Page_Load, when the user selects another listitem, the selection they have chosen is overridden by the selection delcared in Page_Load.

Any ideas on how to resolve this guys? Thanks


In your specific case you can try this:

include a query string param in your redirection query string. which indicate that user has selected a value.

in your page_load method check that query string param has that value , and set again for that drop down list.


Why are u redirecting it? page redirect can not retrieve the viewstate value (they are vanished when u do) instead set autopostback property of DropDownList to true and then use the DropDownList.SelectedValue or Text property on the DropDownList event

you can also set the value in the Onprerender event of the page if you need to do it with a query string


do not need to redirect just set dropDownList1.AutoPostBack=True;
or
set AutoPostBack to True from properties Window

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜