开发者

ASP.NET Binding with EVAL

I'm trying to do the following for asp.net combobox:

Text='<%# IIf(Eval("Name").ToString().Equals(""), Bind("Other"), Bind("Name") %>'  

What I'm trying to do is if the "开发者_运维技巧Name" column is empty then bind to "Other" column, otherwise bind to "Name" column.

Anyone know the right syntax, keep getting object not set to reference. I'm doing this in VB.Net.

Thanks,

Jim


Try this (Edited)

Text='<%# If(Not Eval("Name").ToString.Length = 0, Eval("Name") , Eval("Other")) %>' 

If this doesn't work, then you might have to build a Code Behind method

Text='<%# RetrieveName(Eval("Name"),Eval("Other"))'

Code Behind

Public Function RetrieveName(Byval name As String?, Byval other As String?) As String
  If Not String.IsDBNull(name) Then
    return name
  ElseIf String.IsDBNull(name) AndAlso Not String.IsDBNull(other) Then
    return other
  Else
    return String.Empty
  End If
End Function


Try

Text='<%# IIf(Eval("Name").Equals(DBNull.Value), Eval("Other") , Eval("Name")) %>' 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜