使用Linq排名对项目进行排序 - 更新面板 [英] Sorting Items with Linq Ranking - Update Panel
本文介绍了使用Linq排名对项目进行排序 - 更新面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我有一个更新面板,列出了数据源中的项目。该面板允许用户按照他们的意愿按顺序上下移动项目。
代码后面的数据已在类型类的List中检索,并使用linq的排名来将索引向上或向下移动一个。
我似乎无法让这个工作,并且谷歌也是如此。
请帮助。
更新面板用户界面
Hi There,
I have an update panel listing items from a data source. The panel allows users to move items up or down in the order as they wish.
Code Behind data has been retrieved in a List of type class and using ranking for linq to either shift the index one up or one down.
I cannot seem to get this to work and have Google it as well.
Any Help please.
Update Panel User Interface
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="btnUp" runat="server" OnClick="btnUp_Click" ImageUrl="~/Content/up-arrow.png" CommandName="ParamUp" CommandArgument='<%# Container.DataItemIndex %>' AlternateText="Up" />
<asp:ImageButton ID="btnDown" runat="server" OnClick="btnDown_Click" ImageUrl="~/Content/down-arrow.png" CommandName="ParamDown" CommandArgument='<%# Container.DataItemIndex %>' AlternateText="Down" />
</ItemTemplate>
<ItemStyle Wrap="False" />
</asp:TemplateField>
代码背后 - 移动一个
Code Behind - Move one up
dbCoCParamElements[index - 1].Rank = dbCoCParamElements[index].Rank;
dbCoCParamElements[index].Rank = dbCoCParamElements[index].Rank - 1;
dbCoCParamElements = dbCoCParamElements.OrderBy(fe => fe.Rank).ToList();
代码背后 - 向下移动
Code Behind - Move one down
dbCoCParamElements[index + 1].Rank = dbCoCParamElements[index].Rank;
dbCoCParamElements[index].Rank = dbCoCParamElements[index].Rank + 1;
dbCoCParamElements = dbCoCParamElements.OrderBy(fe => fe.Rank).ToList();
推荐答案
通过执行修复在将其作为列表的索引进行排名之前的第一个订单将在每行更改后被拧紧。
Fixed by doing an order by first before ranking it as the index of the List will be screwed after each row change.
dbCoCParamElements = dbCoCParamElements.OrderBy(fe => fe.Rank).ToList();
dbCoCParamElements[index - 1].Rank = dbCoCParamElements[index].Rank;
dbCoCParamElements[index].Rank = dbCoCParamElements[index].Rank - 1;
dbCoCParamElements = dbCoCParamElements.OrderBy(fe => fe.Rank).ToList();</pre>
这篇关于使用Linq排名对项目进行排序 - 更新面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文