This is an interesting thing I did few days ago while I was working in my office. Suppose the DDL(Dropdownlist) is containing some items. You wanna select one from the list programmatically at runtime. Generally at first I tried to do in this way:
MyDDL.Text="item text";
But this will not work and actually it will not also show any error. You will just try and try but nothing will happen. So we need to click the right way.
As we already saw the two things for databound DDL is:
* DataTextField
* DataValueField
Suppose Subcategorydesc=dataTextField
SubCatID=datavaluefield
And we want to select a subcategory called "Marketing" having subcatid=3. Then the code will be like this:
MyDDL.Items.getByValue("3").Selected=true;
thanks
Masud.
No comments:
Post a Comment