Hi Sulabh,
I have created sample code which full-fill your requirement.
HTML
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="ddlCustomers" Width="200px" CssClass="form-control" runat="server">
</asp:DropDownList>
</div>
<div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
</div>
</form>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.PopulateCustomers();
}
}
private void PopulateCustomers()
{
string constring = ConfigurationManager.ConnectionStrings["Constring"].ConnectionString;
using (SqlConnection con = new SqlConnection(constring))
{
using (SqlCommand cmd = new SqlCommand("Select CustomerId,Name FROM Customers", con))
{
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
ddlCustomers.DataSource = dt;
ddlCustomers.DataTextField = "Name";
ddlCustomers.DataValueField = "CustomerId";
ddlCustomers.DataBind();
ddlCustomers.Items.Insert(0, new ListItem("====SELECT====", "0"));
}
}
}
Vb.Net
Protected Sub Page_Load(sender As Object, e As EventArgs)Handles Me.Load
If Not IsPostBack Then
Me.PopulateCustomers()
End If
End Sub
Private Sub PopulateCustomers()
Dim constring As String = ConfigurationManager.ConnectionStrings("Constring").ConnectionString
Using con As New SqlConnection(constring)
Using cmd As New SqlCommand("Select CustomerId,Name FROM Customers", con)
Dim sda As New SqlDataAdapter(cmd)
Dim dt As New DataTable()
sda.Fill(dt)
ddlCustomers.DataSource = dt
ddlCustomers.DataTextField = "Name"
ddlCustomers.DataValueField = "CustomerId"
ddlCustomers.DataBind()
ddlCustomers.Items.Insert(0, New ListItem("====SELECT====", "0"))
End Using
End Using
End Sub