topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Tuesday April 16, 2024, 9:27 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Rearranging one item within a dataset  (Read 3352 times)

h0meopathic

  • Participant
  • Joined in 2007
  • *
  • default avatar
  • Posts: 24
    • View Profile
    • Donate to Member
Rearranging one item within a dataset
« on: December 15, 2009, 12:55 PM »
I've got a list of people coming in from a stored procedure alphabetically, stored in a dataset, bound to a custom datasource, then displayed in the order that they came in

on.
Code: C# [Select]
  1. protected void gvPhotoGrid_OnItemDataBound(object sender, DataListItemEventArgs e)
  2.     {
  3.         if (e.Item.ItemType == ListItemType.AlternatingItem | e.Item.ItemType == ListItemType.Item)
  4.         {
  5.             Label l = (Label)e.Item.FindControl("lblTitle");
  6.            
  7.             if (l != null)
  8.             {
  9.                 string strval = l.Text;
  10.                 string title = _title;
  11.  
  12.                 if (title == strval)
  13.                 {
  14.                     l.Text = "";
  15.                     e.Item.Visible = false;
  16.                 }
  17.                 else
  18.                 {
  19.                     title = strval;
  20.                     _title = title;
  21.                     l.Text = "<br/>" + title;
  22.                     e.Item.Visible = true;
  23.                 }
  24.             }
  25.         }
  26.     }

My problem is, two people got a divorce and can't be next to each other. They both have the same last name so by default they would come in to the list right next to each other. So, what would be the logic to display one of the people on the list in a different location without putting them at the bottom or top?

Code: HTML [Select]
  1. <asp:DataList ID="gvPhotoGrid" runat="server">
  2.                 <ItemTemplate>
  3.                 <tr id='<%# Eval("DiaLevelName") %>' align="center">
  4.                     <td colspan="2"><asp:Label ID="lblTitle" Font-Underline="true" Font-Bold="true" runat="server" Text='<%# Bind("DiaLevelName") %>' Visible="true" ></asp:Label>
  5.                     <br />
  6.                     <br />
  7.                     </td>
  8.                 </tr>
  9.                 <tr align="center">
  10.                     <td><a href='<%# ResolveUrl("gemProfile.aspx?gemid=" + Eval("userID") + "&Name=" + Eval("calendarSearch")) %>'>
  11.                                         <asp:Image BorderWidth="0px" ID="Image1" runat="server" AlternateText='<%# Eval("userName") %>'
  12.                                                     ImageUrl='<%#  ResolveUrl("~/images/gemImages/" + Eval("gemImage")) %>' />
  13.                                     </a>
  14.                                     <br />
  15.                                     <asp:Label runat="server" ID="lblName" Text='<%# Eval("userName") %>' />
  16.                                     <br />
  17.                                     <br />
  18.                     </td>
  19.                 </tr>
  20.                 </ItemTemplate>
  21.                 </asp:DataList>

CWuestefeld

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,009
    • View Profile
    • Donate to Member
Re: Rearranging one item within a dataset
« Reply #1 on: December 16, 2009, 02:07 PM »
First, tell those two people to grow up. They can still acknowledge that their previous partner is human. And letting their personal life and professional life overlap (if that's what's happening) is a recipe for problems.

Second, Having to break the natural alphabetic ordering is going to make the application more difficult for everyone else to use.

Third, why not sort by first name instead? Is there any other meaningful sort criteria?