Thursday, November 26, 2015

Dynamically populating DropDown List in asp.net C#

string ss = @"Data Source=VMB-PC\SQLEXPRESS;Initial Catalog=website;Integrated Security=True";
        s = new SqlConnection(ss);
     
        s.Open();
        SqlCommand cmd = new SqlCommand("select *from departments",s);
        SqlDataReader d = cmd.ExecuteReader();
        for (int i = 0; d.Read(); i++)
        {

            DropDownList1.Items.Insert(i, d.GetString(0));
        }

No comments:

Post a Comment