Hi,
In a webform I have some textboxes and ddlist. From MS Sql db I will retrive some values and will display on the textboxes and ddlist.
For textboxes I can do the following
textBox1.Text=dr.GetValue(0).ToString();
textBox2.Text=dr.GetValue(1).ToString();
Now for ddlist what shall I use
ddlist1.????=dr.GetValue(2).ToString();
Thanks
Sachi
Loading
SreekanthPosted Nov 16, 2009, 12:38 AM
while (myReader.Read())
{
ListItem Lst2=new ListItem(myReader[1].ToString(),myReader[0].ToString());
dropdownlis1.Items.Add(Lst2);
}
myReader.Close();
M using datareader insted of dataset... now u can fill value and name of for lisitems in dropdownlist...
keshav singhPosted Nov 16, 2009, 12:28 AM
dropdownlist1.items.add(dr.getvalue(2).tostring());
this is used to add the values in dropdownlist from database
Kirtan PatelPosted Nov 12, 2009, 9:16 AM
as per way you are retrieving data using Data Reader
Requirement is your DropDownList Should be Filled By Items .
Then Select that Value in DLL that you are getting from database using Below code
DropDownList1.Items.FindByText(dr.GetValue(2).ToString()).Selected = true;
Or
if your DropDownlist is Blank then you can also Just Add The Value got From Database to DropDownlist
DropDownList1.Items.Add(dr.GetValue(2).ToString());
DropDownList1.Items[0].Selected = true;
if My answer helps you then check "Do you like this answer" :)