How to Bind Data in DropDownList in ASP.Net with SqlDataSource

by Santhakumar Munuswamy

  Posted on  30 November 2014



Dropdownlist Control:

It is enables users to select from a single-selection drop-down list. The drop-down list contain "n" number of items. The DropDownList control also supports data binding, such as data to bind the control to a data source like object data source, xml data source and sql data source, that contains the items to display in the control. This DropDownList control can be used to add data manually or even dynamically data binding from database.

DataBind Method

It is method to bind the data source to the DropDownList control

DataTextField, DataValueField Property

To specify which field in the data source to bind to the Text and Value properties of each list item in the control.

SelectedIndex Property

The SelectedIndex property to programmatically determine the index of the item selected by the user from the DropDownList control


<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Dropdownlist.aspx.cs" Inherits="Dropdownlist" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head runat="server">
    <title> dropdownlist control</title>
    <form id="form1" runat="server">
    <td style="height: 45px"><asp:Label ID="Label1" runat="server" Style="left: -1px; position: relative; top: 0px"
            Text="Name:" Width="46px"></asp:Label></td>
     <td style="height: 45px"><asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1"
            DataTextField="EmpName" DataValueField="EmpName" Height="26px" Style="left: 3px;
            position: relative; top: 0px" Width="125px">
         <asp:ListItem> &lt;&lt; Select &gt;&gt;</asp:ListItem>
     <td style="height: 45px">
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:masterConnectionString %>"
            SelectCommand="SELECT [EmpName] FROM [tbl_employee_profile]"></asp:SqlDataSource></td>
        <asp:DropDownList ID="DropDownList" runat="server">

source from my old blog: Readmore


About the Author
He is a Technical Lead, C# Corner MVP, Author and founder of the blog, has over 9+ years experience on Microsoft Technologies like C#.Net, ASP.Net, ADO.Net, MVC, WCF, Ajax, IIS, SQL Server, Windows Phone and some developmet tools. He is an actively spending his valuable time to popular .Net Community like C# Corner, Microsoft TechNet Wiki, DZone, Stackoverflow, DotNetSpark and etc.

Follow Me: Facebook, Twitter, Google Plus, LinkedIn
blog comments powered by Disqus

Month List

Community Badges