[英]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.