DropDownList reloading
I have 2 dropdownlists on a WebForm. Dropdownlist1 controls what should display on DropDownList2.
When the page first loads I pass in a selectedindex of 0 to function to load DropDownList2. The data loads perfectly. However when I change the selectedindex on DropdownList1 which causes a postback to recalculate new Dropdownlist2 vales the populating fails. Even though dropdownlist is bound to new datasource that does have data in it. The data loaded in inatial page load remains in DropDownlist2. EnableViewState is = true on Dropdownlist2 and 1.
开发者_如何学CIm developing using asp.net 2.0
I have no idea of why this is failing and would be really grateful if anyone could shed some light on it. Many Thanks Tony
Why not use the Cascading dropdwn in the AJAX Control Toolkit? http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/CascadingDropDown/CascadingDropDown.aspx
If you don't want to do that, make sure that populating DropDown1 occurs within a postback check. Otherwise, the DropdownList1 will be repopulated and the SelectedIndex set to 0 on every postback.
if (!Page.IsPostBack)
{
//Populate DD1
}
精彩评论