ASP.NET中继器绑定列表< string> [英] ASP.NET Repeater bind List<string>
本文介绍了ASP.NET中继器绑定列表< string>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将列表< string>
绑定到Repeater控件。现在我想使用 Eval
函数
在 ItemTemplate
中显示内容,如
I am binding a List<string>
to a Repeater control. Now I want to use the Eval
function
to display the contents in ItemTemplate
like
<%# Eval("NAME") %>.
但我不知道我应该用而不是NAME。
But I am not sure what I should use instead of NAME.
推荐答案
只需使用<%#Container.DataItem.ToString()%>
如果你担心空值,你可能想重构这个
If you are worried about null values you may want to refactor to this
<asp:Repeater ID="repeater" runat="server">
<ItemTemplate>
<%# Container.DataItem?.ToString() ?? string.Empty%>
</ItemTemplate>
</asp:Repeater>
这篇关于ASP.NET中继器绑定列表< string>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文