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
Step 1
Webconfig file
- <connectionStrings>
- <add name="business" connectionString="Data Source=RAM;Initial Catalog=db_business; providerName=" System.Data.SqlClient "/>
- </connectionStrings>
Step 2
Aspx code
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <asp:DropDownList ID="ddlLocation" CssClass="form-control" runat="server" DataSourceID="dsLocation" DataTextField="fld_location" DataValueField="fld_id">
- <asp:ListItem Selected="True">--SELECT--</asp:ListItem>
- </asp:DropDownList>
- <asp:SqlDataSource ID="dsLocation" runat="server" ConnectionString="<%$ ConnectionStrings:business %>" SelectCommand="SELECT fld_id,fld_location FROM dbo.tbl_LOCATION"></asp:SqlDataSource>
- </div>
- </form>
- </body>
- </html>
Output

harshita chaudharyPosted Jun 14, 2017, 1:38 AM
Sir how to do for multiple dropdown list???
Satyaprakash SamantarayPosted Apr 27, 2017, 6:49 AM
Mr . Ramprasath , You put sql query in design mode . Is it safe for real time project . Any one can break your code using sql injection attack.