【问题标题】:"The name 'Bind' does not exist in the current context" when manipulating the result of Bind操作绑定结果时出现“当前上下文中不存在名称‘绑定’”
【发布时间】:2023-03-18 00:06:01
【问题描述】:

我正在尝试将从数据绑定的 gridview 控件检索到的色调值绑定到用于显示该值的文本框的背景色。在为相关列编辑 ItemTemplate 后,我添加了以下代码以从我的数据中获取 Hue 值,将其转换为颜色,然后将其传递给 BackColor 属性:

<asp:TextBox ID="TextBox8" runat="server" BackColor='<%# GetColourFromHue(int.Parse(Bind("Hue"))) %>' ReadOnly="True" Text='<%# Bind("Hue") %>'></asp:TextBox>

但是,我收到以下错误:

CS0103: The name 'Bind' does not exist in the current context

问题在于我将 Bind("Hue") 命令包装在更多代码中:GetColourFromHue(int.Parse(Bind("Hue")))

如何操作 Bind 返回的值,以便将其分配给控件属性?

【问题讨论】:

  • 没有办法这样做。 Bind 不是一个简单的方法,它是一个特别认可的结构,只能以这种形式工作:&lt;%# Bind("FieldName") %&gt;Blog post 有更多细节。如果您需要以上任何内容,请使用Eval 并自己进行两种绑定。

标签: asp.net gridview data-binding


【解决方案1】:

感谢@Andrei 的评论,我不能使用 Bind,但我可以使用 Eval。以下作品:

GetColourFromHue(int.Parse(Eval("Hue").ToString()))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-21
    • 2019-12-21
    • 2013-10-02
    • 2014-04-22
    • 2017-06-17
    • 2015-09-11
    • 1970-01-01
    相关资源
    最近更新 更多