如何禁用中继器内的控件

发布于 2024-10-10 15:46:39 字数 1177 浏览 0 评论 0原文

我有一个带有 CheckBoxTextBox 的转发器,我将其绑定到数据源。根据后面代码的条件,我希望能够动态禁用 CheckBoxTextBox

目前,这就是我在 中所拥有的内容:

<td>
    <asp:CheckBox runat="server" 
        onclick="checkbox(this); CheckChildren(this);" 
        Enabled='<%#DataBinder.Eval(Container.DataItem, "DISABLE") %>' 
        Text='<%#DataBinder.Eval(Container.DataItem, "CTEXT") %>' 
        Value='<%#DataBinder.Eval(Container.DataItem, "CVALUE") %>' />
</td>

<td>
    <asp:TextBox runat="server" 
        onkeyup="AppendValues(this);" 
        Enabled='<%#DataBinder.Eval(Container.DataItem, "DISABLE") %>' 
        Width="35px" 
        MaxLength="3" 
        Name='<%#DataBinder.Eval(Container.DataItem, "CNAME") %>' 
        CValue='<%3DataBinder.Eval(Container.DataItem, "CNTVALUE") %>'>
    </asp:TextBox>
</td>

#DataBinder.Eval(Container.DataItem, "DISABLE") 被设置为字符串值 " true”,但当代码运行时,我收到一个 InvalidCastException 异常。

我做错了什么?

I have a repeater with a CheckBox and a TextBox, that I am binding to a data source. Depending on conditions from the code behind, I want to be able to disable the CheckBox and TextBox dynamically.

Currently this is what I have within the <ItemTemplate>:

<td>
    <asp:CheckBox runat="server" 
        onclick="checkbox(this); CheckChildren(this);" 
        Enabled='<%#DataBinder.Eval(Container.DataItem, "DISABLE") %>' 
        Text='<%#DataBinder.Eval(Container.DataItem, "CTEXT") %>' 
        Value='<%#DataBinder.Eval(Container.DataItem, "CVALUE") %>' />
</td>

<td>
    <asp:TextBox runat="server" 
        onkeyup="AppendValues(this);" 
        Enabled='<%#DataBinder.Eval(Container.DataItem, "DISABLE") %>' 
        Width="35px" 
        MaxLength="3" 
        Name='<%#DataBinder.Eval(Container.DataItem, "CNAME") %>' 
        CValue='<%3DataBinder.Eval(Container.DataItem, "CNTVALUE") %>'>
    </asp:TextBox>
</td>

The #DataBinder.Eval(Container.DataItem, "DISABLE") is being set to the string value of "true" on the code behind yet when the code is ran, I receive an InvalidCastException exception.

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

屋顶上的小猫咪 2024-10-17 15:46:39

您需要将 boolean 值传递给 Enabled 属性。尝试这样的事情

bool.Parse(DataBinder.Eval(Container.DataItem, "DISABLE").ToString())

You need to pass a boolean value to the Enabled property. Try something like this

bool.Parse(DataBinder.Eval(Container.DataItem, "DISABLE").ToString())
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文