0

I'm trying to create a blog page using a ListView. I am creating a reply function which adds a other css style to the listview when the message contains a parentmessageid.

This is working. Now I need to change the order of the message so the reply message will be placed under the parentmessage. Below you will find my implementation:

Function for datasource to fill the Listview:

protected void LoadMessages(int userid)
{
    Bericht berichten = new Bericht();
    if (berichten.LaadBerichten(userid).Tables.Count > 0)
    {
        ListViewMessages.DataSource = berichten.LaadBerichten(userid);
        ListViewMessages.DataBind();
    }
}

Function to add css style on items where LabelMessageID contains a value:

protected void ListItemMessages_Load(object sender, EventArgs e)
{
    HtmlGenericControl li = (HtmlGenericControl)sender;
    ListViewItem container = (ListViewItem)li.NamingContainer;
    Label LabelParentMessageID = (Label)container.FindControl("LabelParentMessageID");

    if (LabelParentMessageID.Text != string.Empty)
    {
        li.Attributes.Add("class", "reply");
    }
}

ASP.NET ListView Source:

<asp:ListView ID="ListViewMessages" runat="server">
    <ItemTemplate>
        <li id="ListItemMessages" runat="server" onload="ListItemMessages_Load">
            <img src="<%# Eval("[imagelocation]")%>" alt="image" />
            <div class="top-pointer"></div>
            <div class="pointer"></div>
            <!--Hidden Controls-->
            <asp:Label ID="LabelMessageID" runat="server" Text='<%# Eval("[messageid]")%>' Visible="false"></asp:Label>
            <asp:Label ID="LabelParentMessageID" runat="server" Text='<%# Eval("[parentmessageid]")%>' Visible="false"/>
        </li>
    </ItemTemplate>
</asp:ListView>

Can someone help me out with changing the order of the items? Because I have no idea how to accomplish this.

2 Answers 2

0

try something like ds.Tables[0].DefaultView.Sort = "SortField DESC";

2
  • forgot to mention that 'berichten.LaadBerichten' is a dataset; and I cannot order by date or anything.. it should be ordered by the parent id of the message.
    – Mitchell
    Commented Jun 23, 2014 at 9:36
  • try something like ds.Tables[0].DefaultView.Sort = "SortField DESC";
    – Yagzii
    Commented Jun 23, 2014 at 9:40
0

Solved using a SQL stored procedure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.