Reputation: 243
I have 2 dropdownlists, the 1st dropdownlist is bind to the second dropdownlist. If the second dropdownlist has only one item, this item cannot be selected and hence any function cannot be triggered. I went to any related answers that have already been uploaded...but it didn't help... It's important. Can someone help me out in this issue?
Upvotes: 0
Views: 2240
Reputation: 16144
Just add a default ListItem to your second dropdown.
Eg.
<asp:ListItem Text="--Select--" Value="-1"></asp:ListItem>
You can add from c# also: Write this after you have populated dropdownlist from your datasource.
DropDownList1.Items.Insert(0, new ListItem("--Select--", "-1"));
Upvotes: 0
Reputation: 103348
this item cannot be selected and hence any function cannot be triggered
This item can't be selected, as its already selected. Therefore your onchange
event etc, won't be triggered as its not being changed.
You have 2 options:
onload
as well as onchange
. Therefore when the page loads the cascaded dropdown will be populated as well:.
protected void Page_Load(){
BindCascadeDropDown();
}
protected void ddl_onchange() {
BindCascadeDropDown();
}
protected void BindCascadeDropDown(){
//Bind here
}
Upvotes: 2