DropDownList.SelectedIndex doesn't work after Databind

G

Guest

I have a dropdownlist which will jump to another page when selection change.
The onChange handler is done by JavaScript rather than setting AutoPostBack
to true. ViewState is disabled since the page do not post back to itself.

In the Page_onLoad, the DropDownList bind to datasource and databind() is
called.
After that, I want to hardcode the SelectedIndex however it doesn't work.

//code in Page_onLoad

DataView dv = dt.DefaultView;
dv.Sort = "Date DESC";
DDL.DataSource = dv;
DDL.DataTextField = "date";
DDL.DataValueField = "url";
DDL.DataBind();
DDL.SelectedIndex = 2; // <- doen't work

the DDL always select the first option
 
E

Eliyahu Goldin

This looks fine. Make sure there is nothing tampering with ddl setting after
page load either on server or client side.

Eliyahu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top