Today, I have provided an article, which exhibits how to bind a dropdown list with a database without a backend code page in ASP.NET. In this blog, we will create a table in a SQL Server database and bind the table with a dropdown list control. This is an easy way to bind a dropdown list, using the database values in an HTML page. Here, I will write a SQL query in Sqldatasource. There is no need to use the code backend page.

Step 1
Webconfig file
  1. <connectionStrings>
  2. <add name="business" connectionString="Data Source=RAM;Initial Catalog=db_business; providerName=" System.Data.SqlClient "/>
  3. </connectionStrings>

Step 2

Aspx code
  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <head runat="server">
  3. <title></title>
  4. </head>
  5. <body>
  6. <form id="form1" runat="server">
  7. <div>
  8. <asp:DropDownList ID="ddlLocation" CssClass="form-control" runat="server" DataSourceID="dsLocation" DataTextField="fld_location" DataValueField="fld_id">
  9. <asp:ListItem Selected="True">--SELECT--</asp:ListItem>
  10. </asp:DropDownList>
  11. <asp:SqlDataSource ID="dsLocation" runat="server" ConnectionString="<%$ ConnectionStrings:business %>" SelectCommand="SELECT fld_id,fld_location FROM dbo.tbl_LOCATION"></asp:SqlDataSource>
  12. </div>
  13. </form>
  14. </body>
  15. </html>

Output