DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: Rearranging one item within a dataset  (Read 5,162 times)

h0meopathic

  • Participant
  • Joined in 2007
  • *
  • Posts: 24
Rearranging one item within a dataset
« on: December 15, 2009, 06: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: (csharp)
protected void gvPhotoGrid_OnItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem | e.Item.ItemType == ListItemType.Item)
        {
            Label l = (Label)e.Item.FindControl("lblTitle");
            
            if (l != null)
            {
                string strval = l.Text;
                string title = _title;

                if (title == strval)
                {
                    l.Text = "";
                    e.Item.Visible = false;
                }
                else
                {
                    title = strval;
                    _title = title;
                    l.Text = "<br/>" + title;
                    e.Item.Visible = true;
                }
            }
        }
    }

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: (html4strict)
<asp:DataList ID="gvPhotoGrid" runat="server">
                <ItemTemplate>
                <tr id='<%# Eval("DiaLevelName") %>' align="center">
                    <td colspan="2"><asp:Label ID="lblTitle" Font-Underline="true" Font-Bold="true" runat="server" Text='<%# Bind("DiaLevelName") %>' Visible="true" ></asp:Label>
                    <br />
                    <br />
                    </td>
                </tr>
                <tr align="center">
                    <td><a href='<%# ResolveUrl("gemProfile.aspx?gemid=" + Eval("userID") + "&Name=" + Eval("calendarSearch")) %>'>
                                        <asp:Image BorderWidth="0px" ID="Image1" runat="server" AlternateText='<%# Eval("userName") %>' 
                                                    ImageUrl='<%#  ResolveUrl("~/images/gemImages/" + Eval("gemImage")) %>' />
                                    </a>
                                    <br />
                                    <asp:Label runat="server" ID="lblName" Text='<%# Eval("userName") %>' />
                                    <br />
                                    <br />
                    </td>
                </tr>
                </ItemTemplate>
                </asp:DataList> 

CWuestefeld

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,009
    • Participated in NANY Challenge Once
Re: Rearranging one item within a dataset
« Reply #1 on: December 16, 2009, 08: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?


Original address: https://www.donationcoder.com/forum/index.php?topic=21002.0