Bind DropDownList With Month Name without DataBase Using Asp.net

Introduction

In this article we will learn how to dynamically bind the DropDownList with a month name using Globalization, often there is a need for Month Names but developers often refer to a DropDownList of months bound from a database table which is very time consuming and increases the complexity of the code. To overcome this problem we can use the Globalization namespace which is available in ASP.Net.

So let us start with the basics.

DDmontbind.png

What is Globalization or System.Globalization Namespace ?
 
System.Globalization contains classes that define culture-related information, including the language, the country or region, the calendars in use, the format patterns for dates, currency and numbers, and the sort order for strings.
 
Now I hope you understand the basic concepts and  use of System.Globalization. Now let us proceed to develop an application which dynamically binds the DropDownList with Month names using System.Globalization step-by-step.

Start by creating a website as:

  1. Start - All Programs - Microsoft Visual Studio 2010
  2. File - New Website - C# - Empty website (to avoid adding a master page)
  3. Give the web site a name such as Bind DropDownList or whatever you wish and specify the location
  4. Then right-click on Solution Explorer - Add New Item - Default.aspx page
  5. Drag and drop one dropdownlist in the <form> Section of the Default.aspx page
Open the source view. The source code <form> tag should be as in the following:

Formsource.png

Now switch to "View Code" and declare the NameSpace at the top of the Default.aspx.cs page as in:

Namespace.png

Now create the one method named DD_Monthbind() or as you wish to bind the DropDownList use the following code in it.

Now call the DD_Monthbind() method at page load event as:

Pageload.jpg

Now run the application, the output will be as in the following::
 
output.png
 
Summary

From the preceding all examples we have learned how to bind the DropDownList with month names. I hope you understand it. Download the zip file of the sample application.

Up Next
    Ebook Download
    View all
    Learn
    View all