如何禁用中继器内的控件
我有一个带有 CheckBox
和 TextBox
的转发器,我将其绑定到数据源。根据后面代码的条件,我希望能够动态禁用 CheckBox
和 TextBox
。
目前,这就是我在
中所拥有的内容:
<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?
您需要将
boolean
值传递给Enabled
属性。尝试这样的事情You need to pass a
boolean
value to theEnabled
property. Try something like this