• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 246
  • Last Modified:

select a drop down.

I am retrieving data from a table and want have the value that I want as the selected value for a drop down. How do I loop through the drop down and make the value dtUserExist.Rows[0]["gender"].ToString() match what is in the options of the dropdown and then make it the selected index?
The name of the dropdown is called "Gender". Please advise?
0
solraccheffy
Asked:
solraccheffy
1 Solution
 
s_sansanwalCommented:
try this
                  string data = dtUserExist.Rows[0]["gender"].ToString();
                  data = data.ToLower();
                  for(int index = 0; index < this.Gender.Items.Count; index++)
                  {
                        string item = this.Gender.Items[index].ToString();
                        if(item.ToLower() == data)
                        {
                              this.Gender.SelectedIndex = index;
                              break;
                        }
                  }


Cheers,
S Sansanwal
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now