بایند DropDownList از بانک اطلاعات
بایند DropDownList از بانک اطلاعات
string strConnection = WebConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ToString();
string strCmd = "SELECT menuid,menuname FROM trmenu where parentid=0";
SqlConnection con = new SqlConnection(strConnection);
SqlCommand cmd = new SqlCommand(strCmd, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
try
{
con.Open();
da.Fill(ds);
DropDownList1.DataSource = ds;
DropDownList1.DataBind();
}
finally
{
con.Close();
}
string strCmd = "SELECT menuid,menuname FROM trmenu where parentid=0";
SqlConnection con = new SqlConnection(strConnection);
SqlCommand cmd = new SqlCommand(strCmd, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
try
{
con.Open();
da.Fill(ds);
DropDownList1.DataSource = ds;
DropDownList1.DataBind();
}
finally
{
con.Close();
}