-->

Tuesday, April 28, 2015

How to bind Dropdownlist with whole english characters in ASP.NET C#

How to bind Dropdownlist with whole english characters in ASP.NET C#

I want to say that how to add English alphabets at run time in DropdownList. A intermediate programmer know that each char contain a ASCII value like 65 is a ASCII value of letter 'A'. Similarly again 66 to 90 is a ASCII value of Letter B to Z.  So add a DropdownList in the design page also bind with Alphabet public property. Look like this:

Source page:
<asp:DropDownList ID="Letters" DataSource='<%# Alphabet %>' runat="server" />

Code Behind Page:
public partial class Bynamejobsearch : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            DataBind();
        }
    }
    private List<char> _Alphabet;
    protected List<char> Alphabet
    {
        get
        {
            if (_Alphabet == null)
            {
                _Alphabet = new List<char>();
                for (int i = 65; i < 91; i++)
                {
                    _Alphabet.Add(Convert.ToChar(i));
                }
            }
            return _Alphabet;
        }
    }
}
In this program i have a list of type char. Use for loop which is start from 65 to 90. Add this char in the list one by one.

How to bind Dropdownlist with whole english characters in ASP.NET C#

Read other related articles

Also read other articles

© Copyright 2013 Computer Programming | All Right Reserved