.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Melody Anderson

Home >> Articles >> ASP.NET >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Bind Data in Dropdown List Control in ASP.NET using SQLDataSource

Posted By:Santhakumar Munuswamy       Posted Date: December 27, 2015    Points: 200    Category: ASP.NET    URL: http://www.dotnetspark.com  

This article explains how to Bind data in Dropdown List control in ASP.NET using SQLDataSource.


In this article, I explained how to bind data to Dropdown List control using SQLDataSource in web application in Asp.net 

Dropdownlist Control

It's enables users to select from a single-selection drop-down list. The drop-down list contains "n" number of items.

The DropDown List 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 DropDown List control can be used to add data manually or even dynamically data binding from database.

DataBind Method

The method to bind the data source to the DropDown List 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 DropDown List control.


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Dropdownlist.aspx.cs" Inherits="Dropdownlist" %>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
    xmlns="http://www.w3.org/1999/xhtml" >  
    <head id="Head1" runat="server">  
        <title>Asp.Net 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 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><< Select >>  
                        <td style="height: 45px">  
                            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:masterConnectionString %>"   
SelectCommand="SELECT [EmpName] FROM [tbl_employee_profile]">  
                <asp:DropDownList ID="DropDownList" runat="server"></asp:DropDownList>  


You can also read this article in my blog here

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend