Select DropDownList item after declarative DataBinding

Select DropDownList item after declarative DataBinding

The declarative controls of ASP.NET are really great. However, there are some times, when it may not seem so.
Let’s say you have a DropDownList which is bound by a DataSource control.

Also, you have other pages hitting this page, with querystrings, and based on the item in the querystring, you’d like the to select that item.
In ASP.NET, you’d just code it, and select it after the code, or in the Pre-render event.

DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(DropDownList1.Items.FindByText(Request.Querystring("YourQuerystring"));

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *