i have a droplist in page that i bind this with code
Category catObj = new Category();
dropCat.DataSource = catObj.GetAllCategory();
dropCat.DataTextField = "Title";
dropCat.DataValueField = "CategoryID";
dropCat.DataBind();
i want change selected item of droplist with ths code
dropCat.SelectedIndex = Convert.ToInt32(catObj.ParentId);
but this code cant change the selected item
please help me
thank you all
I’ll assume that you’re trying to select by value and not by index since
catObj.ParentIdis likely to contain a CategoryId. In case my assuption is correct, you’ll need to do thisDropDownList.SelectedIndexproperty refers to a position inside Items collection and not about the value of the item.