python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
DropDownList in ASP.NET using C#

DropDownList in ASP.NET using C#

Hello everyone,

In this post, i'm going to share to code-sample for bind country list in dropdownlist in using C#.

This example is simple and easily understandable DropDownList code-sample using with c# 

Table of Contents

1. In the 1st steps, code-sample for aspx page
2. In the 2nd steps, code-sample for C# (.cs page)

In the 1st step, we write the code for view in page i.e. .aspx

<asp:DropDownList ID="DDLLocation" runat="server" OnSelectedIndexChanged="DDLLocation_SelectedIndexChanged"
    <asp:ListItem Text="Select Location" Selected="true"></asp:ListItem>
    <asp:ListItem Value="Nda">Utter Pradesh</asp:ListItem>
    <asp:ListItem Value="chi">Delhi</asp:ListItem>
    <asp:ListItem Value="Ambd">Ranchi</asp:ListItem>
    <asp:ListItem Value="us">USA</asp:ListItem>
    <asp:ListItem Value="kral">Kerela</asp:ListItem>
In the 2nd step, we write the code for cs file in page i.e. .aspx.cs

/// <summary>
/// DropdownList Selected Index Changed evets.
/// </summary>
protected void DDLLocation_SelectedIndexChanged(object sender, EventArgs e)

/// <summary>
/// Get the Country details and bind the data in grid view.
/// </summary>
public void getRecordbyLocation()
    String connString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;

    SqlDataAdapter da = new SqlDataAdapter("SP_getRecords", connString);

    da.SelectCommand.CommandType = CommandType.StoredProcedure;
    da.SelectCommand.Parameters.AddWithValue("@Location", DDLLocation.SelectedItem.Text);

    DataSet dsObj = new DataSet();

    GridViewID.DataSource = dsObj.Tables[0];



Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - and
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like Powered by Blogger.
ASK Questions