0

I have a field where I want to show something. I want to display any value related to that row and if else method becomes pretty long. I tried something like this:

<%#Eval("col1")??Eval("Col2")%>

It didn't work. Then I tried this:

<%#Eval("col1").ToString() ?? Eval("Col2").ToString()%>

It didn't work either. Am I doing something wrong or is it not possible this way?

4

2 回答 2

0

您可以使用公共方法完成此任务

public string bindVal(object myval)
{
if (myval == null)
{
 return "NA value";
}

 return myVal.ToString();
}

标签代码:

<asp:Label ID="lblmyvalue" Text='<%# testbind(Eval("myvalue1")) %>' runat="server"></asp:Label>

或者你可以使用

<%#(String.IsNullOrEmpty(Eval("myvalue1").ToString()) ? "NA" : Eval("myvalue1"))%>
于 2013-10-18T17:52:47.210 回答
0

不要将其转换为字符串。您的第一行应该有效(为我工作):

<%# Eval("Col1")??Eval("Col2") %>
于 2013-10-18T20:45:29.367 回答