Search code examples
c#asp.netsql-serverdropdownlistfor

How to bind a sql column to a drop down list?


I have a drop down list. I want to set its items to a column of my data base table.
how can I do?

 <asp:DropDownList ID="MyControlsList" runat="server">
     <asp:ListItem></asp:ListItem>
 </asp:DropDownList>  

I have a table that saves the list of my controls title. I want to know how to set Items in list Item?


Solution

  • I think you not googled your problem if you then you will get lots of answer. This is how to Bind Dropdown list.

    DropDownList1.DataSource  = dtTable;  
    DropDownList1.DataTextField = "Name";
    DropDownList1.DataValueField= "Id";
    DropDownList.DataBind();