How to generate alphabets A to Z in asp.net - Free Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server,WCF,Entity framework snippets and tutorial

How to generate alphabets A to Z in asp.net

In this article I am going to explain how to generate alphabets A to Z in asp.net

How to generate alphabets A to Z in asp.net

Implementation:

HTML Markup:
<asp:DataList ID="dtlalphabets" runat="server" RepeatDirection="Horizontal">
            <ItemTemplate>
                <asp:Label ID="lbl" runat="server" Text='<%#Eval("Value")%>' CssClass="lable" ></asp:Label>
            </ItemTemplate>
        </asp:DataList>

Generate Alphabets
Create a method to generate alphabets and show in datalist data control

C# Code:

  protected void Page_Load(object sender, EventArgs e)
    {
            GenerateAlphabetsAtoZ();
    }
    private void GenerateAlphabetsAtoZ()
    {
        try
        {
            List<ListItem> alphabets = new List<ListItem>();

            ListItem alphabet = new ListItem();
            for (int i = 65; i <= 90; i++)
            {
                alphabet = new ListItem();
                alphabet.Value = Char.ConvertFromUtf32(i);
                alphabets.Add(alphabet);
            }
            dtlalphabets.DataSource = alphabets;
            dtlalphabets.DataBind();   
}
        catch(Exception ex)
        { }
    }

VB.net Code:
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
            GenerateAlphabetsAtoZ()
    End Sub
    Private Sub GenerateAlphabetsAtoZ()
        Try
            Dim alphabets As New List(Of ListItem)()
            Dim alphabet As New ListItem()
            For i As Integer = 65 To 90
                alphabet = New ListItem()
                alphabet.Value = [Char].ConvertFromUtf32(i)
                alphabets.Add(alphabet)
            Next
            dtlalphabets.DataSource = alphabets
            dtlalphabets.DataBind()
        Catch ex As Exception
        End Try
    End Sub

What do you think about this article?

If you found this article useful, please share and follow on Facebook, Twitter, Google Plus and other social media websites. To get free updates subscribe to newsletter. Please put your thoughts and feedback in comments section.

Share this

Share on FacebookTweet on TwitterPlus on Google+


EmoticonEmoticon