In ASP.Net Show Favourite Cities on top in a Dropdown List bound to City Table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • arti
    New Member
    • May 2007
    • 13

    In ASP.Net Show Favourite Cities on top in a Dropdown List bound to City Table

    In ASP.Net, I have a Dropdown List bound to a City Table with City Id as Value & City names as Data Text field.
    I want to Show a few Favourite Cities on top as well as in their correct place in the Dropdown List. Help!
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Have you tried doing this in sql?

    Comment

    • dip_developer
      Recognized Expert Contributor
      • Aug 2006
      • 648

      #3
      Originally posted by kenobewan
      Have you tried doing this in sql?
      what is your criteria to make a city favourite???
      I propose to give a Ranking to every city and store it in a field(say city_ranking) in your table

      Now u can easily have your favourite city with a sql like

      SELECT city_name FROM tblCity WHERE city_ranking>50

      Comment

      • arti
        New Member
        • May 2007
        • 13

        #4
        Originally posted by dip_developer
        what is your criteria to make a city favourite???
        I propose to give a Ranking to every city and store it in a field(say city_ranking) in your table

        Now u can easily have your favourite city with a sql like

        SELECT city_name FROM tblCity WHERE city_ranking>50
        User will mark a few cities as favourites- which he might need frequently.
        I want to show favourite city (ranking >10) on top of the list but the complete list should also appear below those cities.
        I need the text & also Value- CityId of each ListItem. As I'll insert the CityId of the selected city in my Prospects Table. I want favourite cities on top as the user should not waste time in searching the list. The ranking can be changed when ever user wishes.
        eg. Dropdown list should look like this:(Delhi has rank 1, Banglore 2 & Hyderabad 3). If I have to enter US,UK prospects, I'll mark NY, London as my favourites.

        Delhi
        Banglore
        Hyderabad
        ----------
        Alicante
        Banglore
        Barcelona
        Basel
        Buchrain Luzern
        Dällikon
        Delhi
        Igualada
        Hyderabad
        Madrid
        Shanghai
        Last edited by arti; Jun 20 '07, 01:06 PM. Reason: some additions

        Comment

        • dip_developer
          Recognized Expert Contributor
          • Aug 2006
          • 648

          #5
          Originally posted by arti
          User will mark a few cities as favourites- which he might need frequently.
          I want to show favourite city (ranking >10) on top of the list but the complete list should also appear below those cities.
          I need the text & also Value- CityId of each ListItem. As I'll insert the CityId of the selected city in my Prospects Table. I want favourite cities on top as the user should not waste time in searching the list. The ranking can be changed when ever user wishes.
          eg. Dropdown list should look like this:(Delhi has rank 1, Banglore 2 & Hyderabad 3). If I have to enter US,UK prospects, I'll mark NY, London as my favourites.

          Delhi
          Banglore
          Hyderabad
          ----------
          Alicante
          Banglore
          Barcelona
          Basel
          Buchrain Luzern
          Dällikon
          Delhi
          Igualada
          Hyderabad
          Madrid
          Shanghai
          If you have a specific Raking system then you can just write the sql as

          SELECT city_name,city_ id FROM tblCity ORDER BY city_ranking

          this sql will give the desired result you want.You can use ASC(Ascending) and DESC(Descending ) clause with ORDER BY according to your Ranking system

          Comment

          • arti
            New Member
            • May 2007
            • 13

            #6
            Originally posted by dip_developer
            If you have a specific Raking system then you can just write the sql as

            SELECT city_name,city_ id FROM tblCity ORDER BY city_ranking

            this sql will give the desired result you want.You can use ASC(Ascending) and DESC(Descending ) clause with ORDER BY according to your Ranking system
            Thanx a lot for your interest.
            I would sort my list if I want Favourite entries on top only. But Pl note that those favourite cities are coming twice- once on top (then a separator) & second time in their normal place (Alphabetical order). And duplicate entries would not be allowed because of duplicate Data Value field. I have seen such lists in some website.
            Delhi
            Banglore
            Hyderabad
            ----------
            Alicante
            Banglore
            Barcelona
            Basel
            Buchrain Luzern
            Dällikon
            Delhi
            Igualada
            Hyderabad
            Madrid
            Shanghai
            Last edited by arti; Jun 21 '07, 12:07 PM. Reason: additions

            Comment

            • Plater
              Recognized Expert Expert
              • Apr 2007
              • 7872

              #7
              I had to do something similar to this.
              After you have binded the dropdown, do an insert at index positions to add them in.

              So say you have a data object with all the items and a data object with all the favorite items. You would bind to the object with ALL the items, then itterate through the object with favorites, using the insert at index function to place them at the top.

              I don't have VS on my computer right now so I can't provide source code, but hopefully that will be enough for you to find what you need.

              Comment

              • arti
                New Member
                • May 2007
                • 13

                #8
                Originally posted by Plater
                I had to do something similar to this.
                After you have binded the dropdown, do an insert at index positions to add them in.

                So say you have a data object with all the items and a data object with all the favorite items. You would bind to the object with ALL the items, then itterate through the object with favorites, using the insert at index function to place them at the top.

                I don't have VS on my computer right now so I can't provide source code, but hopefully that will be enough for you to find what you need.
                Thanks a lot! I had thought that if 2 listitems have same value (CityId) in a list, some problem would be there. But your idea is working!

                Comment

                Working...