How to select all records in a DropDownList

后端 未结 3 1709
遇见更好的自我
遇见更好的自我 2021-01-24 02:06

I have this DropDownList:



        
3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-24 02:42

    following is the way to bind DropDownList from codebehind. visit this link for details

     
     
    

    CODE BEHIND

    SqlConnection con = new SqlConnection(str);
    string com = "select * all from tbl_Cat";
    SqlDataAdapter adpt = new SqlDataAdapter(com, con);
    DataTable dt = new DataTable();
    adpt.Fill(dt);
    
    DropDownList1.DataSource = dt;
    DropDownList1.DataBind();
    DropDownList1.DataTextField = "Categorie";
    DropDownList1.DataValueField = "Cat_ID";
    DropDownList1.DataBind();
    

提交回复
热议问题