我试图将从数据绑定网格视图控件中检索到的色调值绑定到用于显示值的文本框的背面颜色。在为相关列编辑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(&#34; Hue&#34;)命令:GetColourFromHue(int.Parse(Bind("Hue")))
。
如何操作Bind返回的值,以便将其分配给控件属性?
答案 0 :(得分:0)
感谢@Andrei的评论,我不能使用Bind,但我可以使用Eval。以下作品:
GetColourFromHue(int.Parse(Eval("Hue").ToString()))