Question

I have a asp:SqlDataSource and asp:DropDownList components on my page. On normal page it works ok.

Now I'd like to put this on new page with url like ...mypage.aspx?transactionID=2. In Page_Load I would like to set Transaction drop down selected index to 2. But it always binds to 1. I assume, that things happen in this order: in Page_Load I set selected index to 2. Then asp:SqlDataSource's select statement executes and binds to DropDownList. That's why selected index of my DropDownList is always 1, no matter what I set it in Page_Load.

So, how can I bind asp:SqlDataSource to asp:DropDownList and also set it's selected index parameter to some integer?

Was it helpful?

Solution

Write an event handler for the DropDownLists's OnDataBound event to set the selected index after it's bound.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top