Reputation: 25
My first DDL works great:
String BrandID = Request.QueryString["BrandID"];
ddlChoseBrand.Items.FindByValue(BrandID).Selected = true;
My two other dosent work, how shall I write the code correct?
CategoryAccess.GetDllInfo(id);
String ModelID;
String CategoryID;
ddlChoseModel.Items.FindByValue(ModelID).Selected = true;
ddlChoseCategory.Items.FindByValue(CategoryID).Selected = true;
In GetDllInfo I simply get witch one thats going to be selected. So the problem is that I dont know how to write the code correct.
Upvotes: 0
Views: 4238
Reputation: 1
I had this problem too with ddl, but mine was comparing with database. find that .Trim() actually solves the problem.
EG:
ddlChoseCategory.Items.FindByValue(CategoryID.Trim()).Selected = true;
good luck for people who have the same problem as I am. :D
Upvotes: 0
Reputation: 1998
I had the same problem yesterday, It seems like .selected = true doesn't always work as We suppose to..
here is a little workaround you can use instead.
ListItem myitem = ddlChoseModel.Items.FindByValue(ModelID);
ddlChoseModel.SelectedValue = myitem.Value;
peerin mind that selectedValue is a Get property not Get/Set .. but It did worked great with me :D
Good luck :)
Upvotes: 1