ASP.NET与EVAL绑定 [英] ASP.NET Binding with EVAL

查看:202
本文介绍了ASP.NET与EVAL绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做asp.net组合框以下内容:

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.

任何人都知道正确的语法,不断收到未设置为参考对象。我在VB.Net这样做。

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

谢谢,结果
吉姆

Thanks,
Jim

推荐答案

试试这个(编辑)

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

如果这不起作用,那么你可能需要建立一个code方法背后

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

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

code背后

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

这篇关于ASP.NET与EVAL绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆