Dropdownlist DataValueField in asp.net c#

I have multiple items in asp drop down list and I want to set its DataValueField to one by one using loop. I did it as follow.

int cnt = ddl2.Items.Count;
 
for(int j=0;j<cnt;j++)
{
    string val = ddl2.Items[j].ToString();
    int datafieldid = // want datavaluefield id here
}

Please help.

Thanks.

 

Last updated:1/6/2015 11:00:54 PM

1 Answers

Anonymous User
Anonymous User

int cnt = ddl2.Items.Count; 
for(int j = 0;j < cnt ; j++)
{  
    string val = ddl2.Items[j].ToString();
    int datafieldid =  ddl2.Items[j].value // want datavaluefield id here
}

Answer