Click here to Skip to main content
15,570,087 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
List<Country_tbl> listOfCountry = MyDataBase.Country.Liste.Complete;//get list of Country from database

controls.DropDownList.Bind(listOfCountry, ddlCountry );//binding list to ddl
if (Request.Cookies["SelectedCountry"] != null)
{
      string Countryid=Request.Cookies["SelectedCountry"].Value;
      controls.DropDownList.SelectItem(ddlCountry, Countryid);//select item from ddl that have Value==countryid
      List<State_tbl> listOfState = MyDataBase.State.list(Countryid);//BreakPoint: here i check ddlCountry it have One Selected Value
      controls.DropDownList.Bind(listOfState , ddlState);
      //if (Request.Cookies["SelectedState"] != null)
      //{
      //    string Stateid=Request.Cookies["SelectedState"].Value;
      //    controls.DropDownList.SelectItem(ddlState, Stateid);
      //    List<City_tbl> listOfCity = MyDataBase.City.list(Cityid);
      //    controls.DropDownList.Bind(listOfCity , ddlCity);
      //      ///...
      //}
}// BreakPoint: in this point i found that ddlCountry have two Selected value

method Select:

C#
public static void Select(DropDownList ddl, string Value)
{
    ddl.ClearSelection();
    ddl.Items.FindByValue(Value).Selected = true;
}


any one khow why selected value of ddlCountry have been changed?
Posted
Updated 31-Jan-15 8:32am
v2
Comments
Mahmoud_Gamal 31-Jan-15 15:28pm    
i can't know problem with this piece of code but
try to debug on selection changing event on drop down list
and check when call select function the event occur one or more one time
Anisuzzaman Sumon 1-Feb-15 0:00am    
Show your code with event name. and your question is not clear at all .when you are using ddl.ClearSelection() its reset all the selected value .So you need to track item selected each time and store them in a container like listbox .Or you may use dropdownlist with checkboxlist for mutiple selection try the link below
http://www.codeproject.com/Articles/29663/Multiselect-Dropdown-for-Web-Applications
Anurag Gandhi 1-Feb-15 5:18am    
I see that you are using selectItem method in first code snippet, and, Select method in 2nd code snippet. Are you calling wrong method to select a value?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900