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