1

How to bind database table to DropdownList In Asp.net c#


In this article i will bind sql data table into Dropdown list using asp.net c#. i will use dataset and datatable to fetch the data from database and bind it into drop down list.


Step 1. Create a database name it Login.

Step 2. Create a table in Login database name it City_info.



Step 3. Insert Data into sql table (City_info).

2

3
insert into City_info values(1,'Delhi')
4
insert into City_info values(2,'Mumbai')
5
insert into City_info values(3,'Bangalore')
6
insert into City_info values(4,'Chennai')
7
insert into City_info values(5,'Pune')
8
insert into City_info values(1,'Lucknow')
9
insert into City_info values(2,'Jaipur')
10
insert into City_info values(3,'Ghāziābād')
11
insert into City_info values(4,'Indore')
12
insert into City_info values(5,'Vadodara')
13
insert into City_info values(1,'Ludhiāna')
14
insert into City_info values(2,'Āgra')
15
insert into City_info values(3,'Meerut')
16
insert into City_info values(4,'Bareilly')
17
insert into City_info values(5,'Raipur')
18
19 20


Step 4. Open visual studio and create a empty Web application name it Binddatagrid.



Step 5. Add a web form in the application (Binddatagrid) name it binddata.





Step 6. Add a Drop down List control on web form designer side or copy line given below.

21

22
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="binddata.aspx.cs" Inherits="binddata" %>
23
​
24
<!DOCTYPE html>
25
​
26
<html xmlns="http://www.w3.org/1999/xhtml">
27
<head runat="server">
28
    <title></title>
Post settings
Labels
No matching suggestions
Published on
3/19/21 9:20 PM
Permalink
Location
Options
Post published