13
Answers

how to set index of dropdownlist

Photo of Dharmesh sharma

Dharmesh sharma

13y
2.2k
1
hello,

 in my webpage i boud dropdowdlist by sqldatasource.
now i wan to set the selected item 3 of this dropdwonlist

for example:dropdownlist bound with sqldatasource and dropdownllist has a,b,c,d

now i want to search the item in dropdownlist b then select b on page load

how i do that my code not working

i use this code on page load

dropdownlist.SelectedIndex=convert.toint32(dropdownlost.items.findbytext("b").text);

not working

Answers (13)

0
Photo of Vulpes
NA 98.3k 1.5m 13y
Yes, if you know the format and you use (Try)ParseExact, then it doesn't matter about the culture:

      string s = "20110714";
      string f = "yyyyMMdd";
      DateTime dt;
      bool isValid = DateTime.TryParseExact(s, f, null, 0, out dt);
      if (isValid)
      {
         Console.WriteLine(dt);
      }
0
Photo of Jiteendra Sampathirao
NA 6.9k 1.5m 13y

hi,

use this:

string @DOB = DateTime.ParseExact(txtDOB.Text, "dd/MM/yyyy", System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat).ToString("MM/dd/yyyy");
string @DOJ = DateTime.ParseExact(txtDOJ.Text, "dd/MM/yyyy", System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat).ToString("MM/dd/yyyy");

modify this code to you requirement....