请高人指点:DataBinder.Eval 如何处理字符串 (VS.Net 2003)
Aspx页面
<asp:Repeater id= "rpt_list " runat= "server " >
<ItemTemplate >
<tr>
<td nowrap>
<%# ShowUserName(DataBinder.Eval(Container.DataItem, "C_Username ")) %>
</td>
</tr>
===========
后台我是想这么处理的:
public string ShowUserName(obj obj)
{
string str = obj.ToString();
if(obj != null)
str = "Hello " + str;
else
str = " ";
}
============
现在当DataBinder.Eval(Container.DataItem, "C_Username ") 指为Null时就会报错。
请问高手指点。谢谢
------解决方案-------------------- public string ShowUserName(string str)
{
str = str.Trim();
if (str == null || str == string.Empty)
{
return " ";
}
else
{
return "Hello " + str;
}
}
Aspx:
<%# ShowUserName(DataBinder.Eval(Container, "DataItem.C_Username ").ToString()) %>