<%# Container.ItemIndex + 1%>倒过来显示

zjroland 2015-01-03 04:54:05
我有一个<asp:Repeater ID="PollsRepeater" runat="server">
现在需要倒过来显示行号,比如:

5
4
3
2
1,

如果用 <%# Container.ItemIndex + 1%>,显示的是 1,2,3,4,5,请问如何才能倒过来显示行号?
...全文
228 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
你完全可以根本不写任何绑定表达式,但是在 Repeater.DataBind() 之后(此时知道 this.Repeater1.Items.Count 了),遍历一遍所有的行,FindControl 找到所在的列的控件(比如说Label),重新为其设置值。
  • 打赏
  • 举报
回复
引用 4 楼 zjroland 的回复:
public string ProcessCount(object Count) { string strCount = ""; DataView pollsDT = new Business.Polls().GetPollsByID(userID).Tables[0].DefaultView; int count = pollsDT.Count - (int)Count; strCount = count.ToString(); return strCount; }
不要反复调用 GetPollsByID(userID)。
zjroland 2015-01-03
  • 打赏
  • 举报
回复
public string ProcessCount(object Count) { string strCount = ""; DataView pollsDT = new Business.Polls().GetPollsByID(userID).Tables[0].DefaultView; int count = pollsDT.Count - (int)Count; strCount = count.ToString(); return strCount; }
zjroland 2015-01-03
  • 打赏
  • 举报
回复
自己想出来了,用一个处理语句就可以了:<%# ProcessCount(Container.ItemIndex) %>
zjroland 2015-01-03
  • 打赏
  • 举报
回复
问题是那个5是怎么得来的?
三楼の郎 2015-01-03
  • 打赏
  • 举报
回复
<%# 5-Container.ItemIndex %>

62,051

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧