简体   繁体   English

根据listviewitem中的Control更改listview的顺序

[英]Change order of listview based on Control inside listviewitem

I'm trying to create a blog page using a ListView. 我正在尝试使用ListView创建博客页面。 I am creating a reply function which adds a other css style to the listview when the message contains a parentmessageid. 我正在创建一个回复函数,当消息包含parentmessageid时,它将向列表视图添加其他CSS样式。

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: 数据源填充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: 在LabelMessageID包含值的项目上添加CSS样式的函数:

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.NET ListView来源:

<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. 因为我不知道如何实现这一目标。

尝试类似ds.Tables[0].DefaultView.Sort = "SortField DESC";

使用SQL存储过程解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Select 选择 ListView DataTemplate 内的控件时关联的 ListViewItem - Select the associated ListViewItem when selecting a control inside the ListView DataTemplate 使用列表中的项目填充listView控件<ListViewItem> - Populate listView control with items from a List<ListViewItem> 禁用 UWP ListView 控件的 ListViewItem 显示效果 - Disable ListViewItem reveal effect of UWP ListView control 是由ListViewItem的索引引起的ListView.Items顺序? - is ListView.Items order caused by Index of ListViewItem? Listview内的TextBox-在TextBox上获取ListViewItem TextChanged - TextBox inside Listview - getting ListViewItem on TextBox TextChanged 更改ListViewItem的布局<ListView SelectionMode=“Multiple”> - Change layout of ListViewItem when <ListView SelectionMode=“Multiple”> WPF Listview:如何在 CodeBehind 中更改 ListViewItem 的背景? - WPF Listview: How to change background of an ListViewItem in CodeBehind? listview跳过整个控件焦点,将焦点直接设置到listviewitem - listview skip whole control focus, set focus directly to listviewitem ListViewItem 文本未完全显示在 C# windows forms 的列表视图控件上 - ListViewItem text is not shown fully on the listview control of C# windows forms 更新ListView C#(Winforms)内ListViewItem中子项目的值 - Updating the value of a subItem in a ListViewItem inside a listview c# (Winforms)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM