How to bind Dropdownlist Control in ASP.NET

In the previous example we have already discussed about  DropdownList like .

  1. How to change font name at runtime
  2. Bind DropdownList using XML file 

For binding DropdownList using you must use System.Data.SqlClient namespace, which is contains various classes like SqlConnection,SqlCommand etc.

<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
        System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection();
            con.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
            System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
            cmd.CommandText = "insrtdata";
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.Connection = con;
            System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(cmd);
            System.Data.DataSet ds = new System.Data.DataSet();
            DropDownList1 .DataTextField ="Name";
        DropDownList1 .DataValueField  ="Id";
        DropDownList1 .DataSource =ds;
        DropDownList1 .DataBind ();        

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
        <asp:DropDownList ID="DropDownList1" runat="server">

How to bind dropdownlist in

How to bind Dropdownlist Control in ASP.NET How to bind Dropdownlist Control in ASP.NET Reviewed by Jacob Lefore on April 13, 2014 Rating: 5

No comments