Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Dynamically create hyperlinks For English Characters from A-Z

0.00/5 (No votes)
11 Oct 2013 1  
This is how to Dynamicly build the a links of characters from A-Z , somthing like thisA | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P

This articles was originally at wiki.asp.net but has now been given a new home on CodeProject. Editing rights for this article has been set at Bronze or above, so please go in and edit and update this article to keep it fresh and relevant.

This is how to Dynamicly build the a links of characters from A-Z , somthing like this

A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z

You may need to filter a GridView results , like displaying the list of users in which there names begins with specific character .

We can use the Repeater Control to Dynamicly generate the character links  as follows:

ASPX:

            <asp:Repeater ID="Repeater1" runat="server">
                <ItemTemplate>
                    <asp:HyperLink ID="hyp1" runat="server" NavigateUrl='<%# eval("Name","~/Target.aspx?Key={0}") %>'
 Text='<%# eval("Name") %>'></asp:HyperLink>
                </ItemTemplate>
                <SeparatorTemplate>|</SeparatorTemplate>
            </asp:Repeater>

 And the Page Code Behind:

VB:

    Private Sub BindRepeater()

        Dim dt As New Data.DataTable
        dt.Columns.Add("Name")

        Dim c As Char = "A"

        Do While Asc(c) <= Asc("Z")
            dt.Rows.Add(c.ToString())
            c = Chr(Asc(c) + 1)
        Loop Me.Repeater1.DataSource = dt
        Me.Repeater1.DataBind()
    End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        BindRepeater()
    End Sub

C#:

private void BindRepeater() 
{ 
    
    Data.DataTable dt = new Data.DataTable(); 
    dt.Columns.Add("Name"); 
    
    char c = "A"; 
    
    while (Strings.Asc(c) <= Strings.Asc("Z")) { 
        dt.Rows.Add(c.ToString()); 
        c = Strings.Chr(Strings.Asc(c) + 1); 
    } 
    
    this.Repeater1.DataSource = dt; 
    this.Repeater1.DataBind(); 
} 

protected void Page_Load(object sender, System.EventArgs e) 
{ 
    BindRepeater(); 
} 

See Also :

Repeater Web Server Control

Repeater Class

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here