MarchingGazelle MarchingGazelle - 4 months ago 25
Vb.net Question

ASP Repeater not showing data

I'm trying to get an alphabet pager working in

GridView
. It does work, but only one letter shows up in the repeater that I'm using to show the letters. I've read other posts and looked at my code and it seems like it should be working, but it's not.
Any help would be appreciated.

Here is my html

<asp:Repeater ID="rptAlphabets" runat="server">
<ItemTemplate>
<asp:LinkButton ID="lnkBtn1" runat="server" Text='<%#Eval("Value")%>' Visible='<%# Convert.ToBoolean(Eval("Selected"))%>' OnClick="Alphabet_Click"/>
<asp:Label ID="lblAlpha" runat="server" Text='<%#Eval("Value")%>' Visible='<%# Convert.ToBoolean(Eval("Selected"))%>' />
</ItemTemplate>
</asp:Repeater>


Here is my code behind

Private Sub GenerateAlphabets()
Dim alphabets As New List(Of ListItem)()
Dim alphabet As New ListItem
alphabet.Value = "ALL"
alphabet.Selected = alphabet.Value.Equals(ViewState("CurrentAlphabet"))
alphabets.Add(alphabet)
For i As Integer = 65 To 90
alphabet = New ListItem()
alphabet.Value = [Char].ConvertFromUtf32(i)
alphabet.Selected = alphabet.Value.Equals(ViewState("CurrentAlphabet"))
alphabets.Add(alphabet)
Next

rptAlphabets.DataSource = alphabets
rptAlphabets.DataBind()
End Sub


I'm using most of the code from an aspsnippets method.

EDIT :
I'm calling the GenerateAlphabets from my
Page_Load


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try

ClearMessages()
If Not IsPostBack Then
ViewState("CurrentAlphabet") = "ALL"
Me.GenerateAlphabets()
BindGrids()
BindDropDownListBoxes()

End If
Catch ex As Exception
Me.HandleError(ex)
End Try

End Sub

Answer

Change your LinkButton code like this.

<asp:LinkButton ID="lnkBtn1" runat="server" 
        Text='<%#Eval("Value")%>' 
        Visible='<%# Convert.ToBoolean(Eval("Selected")) = False %>'
        OnClick="Alphabet_Click"/>

Reason: You are hiding all LinkButtons that are not currently selected. You should be showing them instead.