aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Show Bind Data to Dropdownlist from Database in C#, VB.NET

Oct 9, 2012

Here I will explain how to bind or show data in dropdownlist from database in using and VB.NET.


In previous posts I explained many articles relating, jQuery, SQL Server, JavaScript. Now I will explain how to bind or show data in dropdownlist from database in using and VB.NET.

Before implement this example first design one table UserInformation in your database as shown below

Column Name
Data Type
Allow Nulls
Int (set Identity=true)
Once table designed in database write the following code in your aspx page

<html xmlns="">
<head runat="server">
<title>how to show data in dropdownlist from database in</title>
<form id="form1" runat="server">
<b>Selected UserName:</b>
<asp:DropDownList ID="ddlCountry" runat="server" />
Now add the following namespaces in code behind

C# Code

using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI.WebControls;
After add namespaces write the following code in code behind

protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)
/// <summary>
/// Bind COuntrydropdown
/// </summary>
protected void BindContrydropdown()
//conenction path for database
using (SqlConnection con = new SqlConnection("Data Source=SureshDasari;Integrated Security=true;Initial Catalog=MySampleDB"))
SqlCommand cmd = new SqlCommand("Select UserId,UserName FROM UserInformation", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
ddlCountry.DataSource = ds;
ddlCountry.DataTextField = "UserName";
ddlCountry.DataValueField = "UserId";
ddlCountry.Items.Insert(0, new ListItem("--Select--", "0"));

Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.UI.WebControls
Partial Class VBSample
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
End If
End Sub
''' <summary>
''' Bind COuntrydropdown
''' </summary>
Protected Sub BindContrydropdown()
'conenction path for database
Using con As New SqlConnection("Data Source=SureshDasari;Integrated Security=true;Initial Catalog=MySampleDB")
Dim cmd As New SqlCommand("Select UserId,UserName FROM UserInformation", con)
Dim da As New SqlDataAdapter(cmd)
Dim ds As New DataSet()
ddlCountry.DataSource = ds
ddlCountry.DataTextField = "UserName"
ddlCountry.DataValueField = "UserId"
ddlCountry.Items.Insert(0, New ListItem("--Select--", "0"))
End Using
End Sub
End Class

If you want to learn more dropdownlist articles check this

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


surendrakumar nimmagadda said...


Vetri said...

I am your fan. I used many of your coding samples in my projects.

But In recent days your articles are very simple and basic things.

Could you please started to post on advanced things like MVC4 articles....


German Alex said...

Thanks Suresh.

K.Ramalingam said...


Gobi Krishnan said...

simply superb

ప్రసాద్ విశ్వనాధ said...

Nice One

laucaroso said...

perfecto, lo mas sencillo que vi en la red, gracias

Anonymous said...


Atul Enjoying with studies said...

Hi suresh i want to display date in dropdown one ddlfor year in which year should be display likewise month and date.
ex:20130501 data in my data base now in page load 2013 in ddlyear and june in dllmonth should be display.
how will i do this.

Anonymous said...

Thanks Friend

Pratibha Pandey said...


Zimasa Yokwana said...

Very helpful, thanks.

ahmed khiran said...

thanks , but i don't repeat the same item in droplistdown ,

such as the droplistdown contain cc ,cc ,cc ,cc , & i hope to see 1 cc not 3

how ?


सोमनाथ चतुर्वेदी said...

Dhanyvaad Guruji

manvir singh said...

hello sir

how i bind drop down list with detail view .....

Mukesh Dutt said...
This comment has been removed by the author.
Mukesh Dutt said...

Thanks solution for add new item for drop list at zero index by the new keyword.

Anonymous said...

how to load country, state, city dropdown list on a gridview's inserting and updating mode using three tier architecture.
I want its solution immediately.

Ritesh Singh said...

Thanks solution for add new item for drop list

Anonymous said...

Thank you. This information was helpful.

Anonymous said...

if selected value filed column data type is varchar then how to chek it with same colun in another table(fk)?

Unknown said...

i have one doubt how to convert the Auto suggestion textbox value to Dropdown list

Thakur Amrendra Kumar said...
This comment has been removed by the author.
Thakur Amrendra Kumar said...

thanks very Nice

Kashyap Bhavsar said...

Thank you is very useful for beginners.
Again thanks

Sachin Kadu said...


Give your Valuable Comments

Other Related Posts

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.