I have 14 Dropdownlist accroding to 7 Days.
Like For a day First dropdown list is Named as From-Time and Second Dropdown list is To-Time.
List Values are Set by 30 minutes Time Difference.
To-Time dropdownlist Should save only those list items which fall after From-time Dropdownlist.like if i select 1 Pm by first then second dropdown list should carry list-items after 1 Pm.
removing is done like this..
protected void ddlMonst_SelectedIndexChanged(object sender, EventArgs e)
{
RemoveListItem(sender as DropDownList,checkboxes);
}
private void RemoveListItem(DropDownList DDl,DropDownList[] checkboxes)
{
int CurrrentSelectedIndex = DDl.SelectedIndex;
String StartDDlName = DDl.ID.Substring(3, 3).ToString() + "ed";
String TargetedDDlName = string.Empty;
for (int i = 0; i < checkboxes.Length; i++)
{
TargetedDDlName = checkboxes[i].ID.Substring(3, 5).ToString() ;
if (StartDDlName.Equals(TargetedDDlName))
{
for(int j=0 ;j<CurrrentSelectedIndex;j++)
checkboxes[i].Items.RemoveAt(0);
}
}
}
but this logic fails if i selected again and again from First Dropdown list.It reomoves all from second one.
How to Handle this situation
Assuming your code is successfully removing the Items, then it makes sense that the To-Time DropDowns could end up being empty after multiple successive selects from the From-Time DropDown(s).
Instead of using
.RemoveAt(), you could.Clear()your To-Time DropDowns and then.Add()the Items from the From-Time DropDown from its SelectedIndex and onwards.You’ll have to modify this to work on your
DropDownList[]