ItemIndex asp:Repeater VB.NET 的内联 IF 语句
我试图在 asp:Repeater 控件内执行内联 IF 语句,以将类添加到第一项,但我似乎不太明白。
基本上我现在拥有的代码不起作用,但应该让我了解我正在“尝试”做什么,如下所示。
<asp:Repeater ID="rptrTabRepeater" runat="server">
<ItemTemplate>
<div class="tab <%= If Container.ItemIndex = 0 Then %>highlight<% End If%>">
'Other stuff here
</div>
</ItemTemplate>
</asp:Repeater>
我尝试使用 OnItemDataBound
事件,但委托接口无法返回值。如果我真的要从代码隐藏函数中执行任何操作,那么它只需要是一个“echo”类型的函数,我不太确定如何在代码隐藏函数中获取项目索引。如果我可以像我的示例一样内联执行一些操作,那对我来说将是最好的解决方案。
也欢迎任何更好的解决方案。谢谢!
编辑:我收到的编译错误是:
Compiler Error Message: BC30201: Expression expected.
I am trying to do an inline IF statement inside a asp:Repeater control to add a class to the first item, but I can't quite seem to figure it out.
Basically the code I have right now that is not working but should give an idea of what I'm "trying" to do looks like this.
<asp:Repeater ID="rptrTabRepeater" runat="server">
<ItemTemplate>
<div class="tab <%= If Container.ItemIndex = 0 Then %>highlight<% End If%>">
'Other stuff here
</div>
</ItemTemplate>
</asp:Repeater>
I have tried using the OnItemDataBound
event but the delegate interface cannot return a value. If I'm going to do anything from a code-behind function really it would just need to be an "echo" kind of function which I wasn't quite sure how to get the item index in a code behind function. If I could do something inline like my example that would be the best solution for me.
Any better solutions welcome as well. Thanks!
EDIT: The compile error I am getting is:
Compiler Error Message: BC30201: Expression expected.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你有没有尝试过类似的事情:
Have you tried something like: