日期:2014-05-18  浏览次数:20380 次

如何repeater下的value项值进行处理
比如有一个
<asp:Repeater   id= "Repeater1 "   Runat= "server ">
    <ItemTemplate>
          '这儿能得到一个  <%#Eval( "authors ")%>       authors在数据库中为如   "赵老一,钱二,孙老三,李四,周五,吴六 "这样的值。 当然,有的时候值为null也有可能。 现在在显示时,如果authors不为空,我想先加一个  " <br> ",再显示第一个作者,然后加   “等”。 而为空的不需要显示,请问应该怎么处理?    
    </ItemTemplate>
</asp:repeater>


或者在repeater中不能实现这个功能要求?

谢谢

------解决方案--------------------
// .aspx
<asp:Repeater id= "Repeater1 " Runat= "server ">
<ItemTemplate>
<%# FormatMyData(Eval( "authors ")) %>
</ItemTemplate>
</asp:repeater>


// .aspx.cs
protected string FormatMyData(object arg) {
if(arg == null) return " ";
return " <br /> " + arg.ToString() + "等 ";
}
------解决方案--------------------
后台 .cs中 添加

protected string getAuthors(string _authors)
{
if(_authors != string.Empty)
{
_authors = " <br/> "+ _authors + "等 ";
}
return _authors;

}

<%#getAuthors(Eval( "authors ").ToString())%>
------解决方案--------------------
楼上的方法差不多了
------解决方案--------------------
前台:
<%# Eval( "authors ").ToString() == " " ? " <br/> "+ Eval( "authors ").ToString()+ "等 " : Eval( "authors ")%>