Populating Data in DropdownList

Sep 8, 2008 at 8:14 AM
Hi all,

I am new to development,i want to fill Dropdownlist from sql server database in C# asp.net application.Can anybody suggest me?
Sep 8, 2008 at 8:56 AM
In the Page_Load()
{
//Open DB Connection
//I think u know how to open DB connection
//Here am taking the products table as example.
//After opening the connection note down the code.


 SqlCommand cmd = null;
 SqlDataReader dr;
  if (!IsPostBack)
        {
            cmd=new SqlCommand("Select pid from product ",con);
            dr=cmd.ExecuteReader();
            while(dr.Read())
            {
                ddlProductId.Items.Add(dr[0].ToString());
            }
            dr.Close();
             }
}