Link to home
Start Free TrialLog in
Avatar of xizwyck
xizwyckFlag for United States of America

asked on

Alphabet paging in VB.Net with Repeater and Gridview

I am relatively new to .Net (in Classic ASP, I could do this) and I'm trying to find a way to create a alphabetical paging gridview that uses a repeater so that when the user clicks the letter, the results are displayed in the gridview.

I have googled and found a few examples of this in C#. I don't have the bandwidth to learn another programming language at the moment and my existing site is using VB anyways.

So, can any point me in the right direction or know where I can find a good example of this function, using VB.Net as codebehind?

Also, I have not had any success with code translators - in my opinion, they don't work well enough on complicated code pieces.

Thank you!
Avatar of atcis
atcis

Can you post how you are reteiving the data?

Basically what I normally do is add link buttons for each letter and databind the repeater again passing the letter as a paramter..

So linkbutton A would call a pass "A%" to your datasource then rebind the repeater.
Avatar of xizwyck

ASKER

I was hoping to use the SqlDataSource ControlParameter that grabs the text from a label, which is created by the repeater. But I have not been able to successfully do this.

So, how do you do what you suggested?
Avatar of xizwyck

ASKER

Does this help?
    <asp:Repeater ID="Repeater1" runat="server" DataSourceID="alphaLetters">
        <ItemTemplate>
            <asp:LinkButton ID="LinkButton1" runat="server"><%#Container.DataItem("alphaList")%></asp:LinkButton>
        </ItemTemplate>
    </asp:Repeater>
 
 
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" DataSourceID="keyWords">
</asp:GridView>
 
 
 
<asp:SqlDataSource ID="alphaLetters" runat="server" 
        ConnectionString="<%$ ConnectionStrings:GTDB %>" 
        SelectCommand="SELECT DISTINCT Left([catName],1) As alphaList FROM [catTbl] ORDER BY Left([catName],1) ASC"></asp:SqlDataSource>
 
<asp:SqlDataSource ID="keyWords" runat="server" 
        ConnectionString="<%$ ConnectionStrings:GTDB %>" 
        SelectCommand="SELECT [catName] FROM [catTbl] WHERE ([catName] = @catQuery)">
    <SelectParameters>
    <asp:ControlParameter Name="catQuery" ControlID="???" Type="String" PropertyName="???" />
    </SelectParameters>
    </asp:SqlDataSource>

Open in new window

Avatar of xizwyck

ASKER

I've been trying and trying... for some reason, I cannot get the linkbutton idea to work. How do I databind a repeater with a linkbutton that when clicked will update the select parameters on a gridview?
Avatar of xizwyck

ASKER

Here is my updated code... now I get a "Permissions denied" error when I click on the linkbutton.

This is the code behind:

    Sub LinkButton_Command(ByVal sender As Object, ByVal e As CommandEventArgs)
        keyWords.SelectParameters("catQuery").DefaultValue = e.CommandArgument
    End Sub
    <asp:Repeater ID="Repeater1" runat="server" DataSourceID="alphaLetters">
        <ItemTemplate>
            <asp:LinkButton ID="LinkButton1" runat="server"
             CommandArgument='<%#DataBinder.Eval(Container.DataItem, "alphaList")%>'><%#DataBinder.Eval(Container.DataItem, "alphaList")%></asp:LinkButton>
        </ItemTemplate>
    </asp:Repeater>
 
 
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" DataSourceID="keyWords" AutoGenerateColumns="False">
    <Columns>
        <asp:BoundField DataField="catName" HeaderText="catName" SortExpression="catName" />
    </Columns>
</asp:GridView>
 
 
 
<asp:SqlDataSource ID="alphaLetters" runat="server" 
        ConnectionString="<%$ ConnectionStrings:GTDB %>" 
        SelectCommand="SELECT DISTINCT Left([catName],1) As alphaList FROM [catTbl] ORDER BY Left([catName],1) ASC"></asp:SqlDataSource>
 
<asp:SqlDataSource ID="keyWords" runat="server" 
        ConnectionString="<%$ ConnectionStrings:GTDB %>" 
        SelectCommand="SELECT [catName] FROM [catTbl] WHERE (Left([catName],1) = @catQuery)">
    <SelectParameters>
    <asp:Parameter Name="catQuery" Type="String" DefaultValue="A" />
    </SelectParameters>
    </asp:SqlDataSource>

Open in new window

Avatar of xizwyck

ASKER

Anyone out there today?
hmm if you can set up a SQL Datasource that takes a session as a parameter and assign it to the field that you are filtering by you can do this in a link button

    Sub LinkButton_Command(ByVal sender As Object, ByVal e As CommandEventArgs)
        Session('YourParam") = "C%"
    End Sub
oops forgot something

   Sub LinkButton_Command(ByVal sender As Object, ByVal e As CommandEventArgs)
        Session('YourParam") = "C%"
         Repeater1.Databind()
    End Sub
Avatar of xizwyck

ASKER

Unfortunately, I can click a link button once, but the gridview doesn't appear, When I click again, I get a "permissions denied" error.

code behind:
   Sub LinkButton_Command(ByVal sender As Object, ByVal e As CommandEventArgs)
        Session("ReqLetter") = e.CommandArgument
    End Sub
    <asp:Repeater ID="Repeater1" runat="server" DataSourceID="alphaLetters">
        <ItemTemplate>
            <asp:LinkButton ID="LinkButton1" runat="server"
             CommandArgument='<%#DataBinder.Eval(Container.DataItem, "alphaList")%>'><%#DataBinder.Eval(Container.DataItem, "alphaList")%></asp:LinkButton>
        </ItemTemplate>
    </asp:Repeater>
 
 
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" DataSourceID="keyWords" AutoGenerateColumns="False">
    <Columns>
        <asp:BoundField DataField="catName" HeaderText="catName" SortExpression="catName" />
    </Columns>
</asp:GridView>
 
<asp:SqlDataSource ID="alphaLetters" runat="server" 
        ConnectionString="<%$ ConnectionStrings:GTDB %>" 
        SelectCommand="SELECT DISTINCT Left([catName],1) As alphaList FROM [catTbl] ORDER BY Left([catName],1) ASC"></asp:SqlDataSource>
 
<asp:SqlDataSource ID="keyWords" runat="server" 
        ConnectionString="<%$ ConnectionStrings:GTDB %>" 
        SelectCommand="SELECT [catName] FROM [catTbl] WHERE (Left([catName],1) = @catQuery)">
    <SelectParameters>
        <asp:SessionParameter Name="catQuery" Type="String" SessionField="ReqLetter" />
    </SelectParameters>
</asp:SqlDataSource>

Open in new window

Avatar of xizwyck

ASKER

I added the DataBind for Repeater1 as well. Still same issue.
Here is a small example of how 3 linkbuttons should be set up. Not usin e.


'these are the first few buttons of the alphabet I have 1 for each letter 
    Protected Sub lbA_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Session("ReqLetter") = "A"
        Repeater1.Databind()
    End Sub
 
    Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Session("ReqLetter") = "B"
        Repeater1.Databind()
    End Sub
 
    Protected Sub LinkButton2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Session("ReqLetter") = "C"
        Repeater1.Databind()
    End Sub

Open in new window

Avatar of xizwyck

ASKER

Ok...  that works but I was hoping to produce linkbuttons dynamically, that reflect items in the database field "catName". For example, as of now, "B" would not show up and I don't want it to appear if it's not there, you know?
Avatar of xizwyck

ASKER

Well, it sort of works. If I happen to click it twice by mistake, it gives me the "permission error".
ASKER CERTIFIED SOLUTION
Avatar of xizwyck
xizwyck
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
xizwyck: I set up something like you did, Repeater control and Gridview. But I wrote a join for the alphabet and the employee list. Now when loaded the employee list loads by default everyone with last name A But how do you get it to change when you click on a letter.

here is a link if you like points for this, Anyone who can answer.

https://www.experts-exchange.com/questions/23838289/repeater-and-Gridview.html