Jacksonville Developers User Group

Learn new things...write better code.
Welcome to Jacksonville Developers User Group Sign in | Join | Help
in
Home Blogs Forums

vb.net Alphabetical filter help for newbie

Last post 08-22-2007, 5:56 PM by tbates. 13 replies.
Sort Posts: Previous Next
  •  08-15-2007, 1:05 PM 1839

    • TM2 is not online. Last active: 09-05-2008, 6:24 AM TM2
    • Top 10 Contributor
    • Joined on 08-15-2007
    • Brunswick, Ga
    • Posts 33
    • Points 0

    Confused [*-)] vb.net Alphabetical filter help for newbie

    Hi,

    Can someone tell me how to (or point me in the right direction)

    implement an alphabetical filter (hyperlink-look) in my web app?

    I currently have a combo-box alphabetical filter that someone was nice enough to post, but I

    prefer the hyperlink flavor and I don't know how to modify it to fit.

    Thanks in advance!

  •  08-15-2007, 2:53 PM 1840 in reply to 1839

    Re: vb.net Alphabetical filter help for newbie

    Private Sub BuildAlphabet()

    Dim alphabet As New List(Of KeyValuePair(Of String, String))()

    Dim c As Char

    For i As Integer = 0 To 25

    c = Convert.ToChar((Convert.ToInt32("A"c) + i))

    alphabet.Add(New KeyValuePair(Of String, String)(c.ToString(), c.ToString()))

    Next

    Me.hyperLinks.DataSource = alphabet

    Me.hyperLinks.DataBind()

    End Sub

     

    <asp:Repeater ID="hyperLinks" runat="server">

    <ItemTemplate>

    <asp:LinkButton ID="alphabetLink" runat="Server" Text='<%# Eval("Value") %>'></asp:LinkButton>

    </ItemTemplate>

    </asp:Repeater>


    There are only 10 types of people in the world: Those who understand binary, and those who don't
  •  08-15-2007, 9:23 PM 1841 in reply to 1839

    Re: vb.net Alphabetical filter help for newbie

    I am just trying to understand the problem . . . are you talking about something similiar to paging a datagrid?  Instead of a having paging (1,2,3, etc) for every ten records or so, you'd have a link for every alpha link (A,B,C, etc) for every group of records in that letter range?

    The Universe has no center and I am it.



    The superior man is modest in his speech, but exceeds in his actions.

  •  08-16-2007, 7:51 AM 1842 in reply to 1841

    • TM2 is not online. Last active: 09-05-2008, 6:24 AM TM2
    • Top 10 Contributor
    • Joined on 08-15-2007
    • Brunswick, Ga
    • Posts 33
    • Points 0

    Re: vb.net Alphabetical filter help for newbie

    Yes, Exactly!

     

  •  08-16-2007, 8:33 AM 1843 in reply to 1842

    Re: vb.net Alphabetical filter help for newbie

    I could probably try for some demo code like Thomas did later tonight, but just brainstorming here . . .

    I'd probably start with a datasource that exposed a couple of methods for retrival (a single letter version, and a letter range [encyclopedia style "A - Am", "An - Ba", etc], and of course an ALL option).  If I were doing ASP.NET 1.1 code, I'd look at the PagedDataSource for handling some of this.

    If I were doing it in ASP.NET 1.1 I'd look at the ItemCreated event of the DataGrid for making my footer (similiar to the code that Thomas provided) and I'd look at the ItemCommand event for handling the clicks of each item, calling the data, and rebinding to the control.

    For ASP.NET 2.0, alot of these features got wrapped write into the GridView, so there is even less work to do after you have your data source set up.

    If you still need a direct demo, I'll whip one up tonite after work, provided someone else here doesnt beat me to it.


    The Universe has no center and I am it.



    The superior man is modest in his speech, but exceeds in his actions.

  •  08-16-2007, 1:06 PM 1844 in reply to 1840

    • TM2 is not online. Last active: 09-05-2008, 6:24 AM TM2
    • Top 10 Contributor
    • Joined on 08-15-2007
    • Brunswick, Ga
    • Posts 33
    • Points 0

    Re: vb.net Alphabetical filter help for newbie

    Thanks for the code.

    I copied and pasted - I'm getting two error messages:

    Type 'List' is not defined.

    &

    Type 'KeyValuePair' is not defined.

     

    In 'Design' view, it looks like it's starting do what I want, just not quite there yet.  Going to try and figure out exactly what your code is doing and see if I can find out what I need to do.  Or you could tell me....... :0)

    For what it's worth, I'm using Visual Web Developer Express 2005.......

     

     

  •  08-17-2007, 9:23 AM 1847 in reply to 1840

    • TM2 is not online. Last active: 09-05-2008, 6:24 AM TM2
    • Top 10 Contributor
    • Joined on 08-15-2007
    • Brunswick, Ga
    • Posts 33
    • Points 0

    Re: vb.net Alphabetical filter help for newbie

    Imports System.Collections.Generic

    I can just hear the groans and imagine the looks of disbelief.  Sorry!

    Don't forget - "Newbie" as in "Totally green".  Please be patient.  I do appreciate any help at all.

    I am getting an error when I try to run the page - Name 'Eval' is not delcared.

    Any ideas?

  •  08-18-2007, 11:04 PM 1848 in reply to 1843

    Re: vb.net Alphabetical filter help for newbie

    Sorry for the lateness of the reply, but life, liberty, and the pursuit of paper often gets in the way.

    My solution is inherently similiar to Thomas' but uses a GridView as I described originally. 

    Start with a GridView Control. You will need something that acts as a datasource.  I used a country list, with name and country code.  I created a small utility class to wrap up access to it, with a GetAllCountries and GetCountriesByAbbreviation methods.

    Next, I wire up the RowCreated event inorder to create the alpha list in the footer

        Private Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
            If e.Row.RowType = DataControlRowType.Footer Then
                For AsciiLetter As Integer = 0 To 25
                    Dim AlphaLinkButton As LinkButton = New LinkButton()
                    AlphaLinkButton.Text = Char.ConvertFromUtf32(AsciiLetter + 65)
                    AlphaLinkButton.CommandArgument = Char.ConvertFromUtf32(AsciiLetter + 65)
                    AlphaLinkButton.CommandName = "AlphabeticalPager"
                    e.Row.Cells(0).Controls.Add(AlphaLinkButton)
    
                    'spacer cheat -- should use CSS instead
                    Dim spacer As New System.Web.UI.HtmlControls.HtmlGenericControl("span")
                    spacer.InnerHtml = " "
                    e.Row.Cells(0).Controls.Add(spacer)
                Next
            End If
        End Sub
    

    This puts the list at the bottom and sets up the links to fire back on the server.  So now we need an event to catch those and reset the list.

        Private Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
            If e.CommandName = "AlphabeticalPager" Then
                GridView1.DataSource = CountriesDataSource.GetCountriesByAbbreviation(Convert.ToChar(e.CommandArgument))
                GridView1.DataBind()
            End If
        End Sub
    

    So that's that.  The real key is the code Thomas already gave you.  The next step is to get it into a GridView or similiar control and handle the server events.

    Let me know is this is helpful or you need anything else.

     

     

     


    The Universe has no center and I am it.



    The superior man is modest in his speech, but exceeds in his actions.

  •  08-20-2007, 12:46 PM 1850 in reply to 1847

    Re: vb.net Alphabetical filter help for newbie

    you may be missing a quote some where.

     

    Text='<%# Eval("Value") %>'


    There are only 10 types of people in the world: Those who understand binary, and those who don't
  •  08-20-2007, 12:57 PM 1851 in reply to 1850

    Re: vb.net Alphabetical filter help for newbie

    Without looking at how you are using it in your solution... you could just explicitly break it down like this.

    Text='<%# DataBinder.Eval(Container.DataItem, "Value") %>'

     


    There are only 10 types of people in the world: Those who understand binary, and those who don't
  •  08-22-2007, 11:07 AM 1856 in reply to 1851

    • TM2 is not online. Last active: 09-05-2008, 6:24 AM TM2
    • Top 10 Contributor
    • Joined on 08-15-2007
    • Brunswick, Ga
    • Posts 33
    • Points 0

    Re: vb.net Alphabetical filter help for newbie

    Okay!

    Finally, the repeater control looks like it should....

    Now, I'm at the point where I actually need to filter my DataSet based on the "clicked"

    alphabetLink.  From what I've been reading on the internet, I need to iterate through the repeater collection and get ItemData.  Is there no simple way to just drill down to the clicked button.

    Like (using the above code from TBates) hyperLinks.alphabetLink.Text?

    Here's what I have and, of course, it doesn't work:

    dtvCust.RowFilter = "LastName LIKE '" & alphabetLink.Text & "%'"

    As you guys can probably already tell, I'm in way over my head.  I thought that I had a beginner to intermediate grasp on vb.net, beginner grasp on asp.net.   HA!  Can somebody recommend a good resource so I can get a grip...That doesn't sound right, but I'm past the point of caring.  Guessing ASP.NET is the source of trouble.

    Any ideas?

    Thanks!

  •  08-22-2007, 11:43 AM 1857 in reply to 1856

    Re: vb.net Alphabetical filter help for newbie

    From the solution that TBates has given you thus far, you could add this into your client side code for your link button . . .

    CommandName="alphaSort" CommandArgument='<%# Eval("Value") %>'

    Then, you could just use the argument in the repeater's ItemCommand event, something like:
        Private Sub hyperLinks_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles hyperLinks.ItemCommand
            If e.CommandName = "alphaSort" Then
                Label1.Text = "You selected: " & e.CommandArgument
            End If
        End Sub
    

    I used a label to display output, but I think you can take it from there to get your dataview filter.


    The Universe has no center and I am it.



    The superior man is modest in his speech, but exceeds in his actions.

  •  08-22-2007, 12:14 PM 1858 in reply to 1857

    • TM2 is not online. Last active: 09-05-2008, 6:24 AM TM2
    • Top 10 Contributor
    • Joined on 08-15-2007
    • Brunswick, Ga
    • Posts 33
    • Points 0

    Re: vb.net Alphabetical filter help for newbie

    It works Perfect!  Thank you!Party!!! [<:o)]
  •  08-22-2007, 5:56 PM 1862 in reply to 1856

    Re: vb.net Alphabetical filter help for newbie

    Well, in my humble opinion, you will not find many books out there with examples for problems such as this.  This just comes from familiarity with ASP.NET and the .NET Framework itself.

    The Oreilly book ASP.NET by Jesse Liberty is a good starting point for ASP.NET.

    The GridViewGuy has quite a collection of how to do some non-"HELLOWORLD" things with gridviews and such.

    Then, of course, there are your fellow JaxDUG members (cheesy and shameless plug, I know).


    There are only 10 types of people in the world: Those who understand binary, and those who don't
View as RSS news feed in XML
Powered by Community Server, by Telligent Systems