为什么我不能在asp:复选框上设置值? [英] Why I can't set a value on a asp:CheckBox?
问题描述
没有属性 Value
:
<asp:CheckBox ID="CheckBox1" runat="server" />
而对于标准HTML:
<input type="checkbox" ID="CheckBox1" value="My Valyue" />
为什么?
推荐答案
Text
属性用于为复选框渲染标签。
The Text
property is used to render a label for the checkbox.
InputAttributes
属性可以添加到:
The control has an InputAttributes
property that you can add to:
myChk.InputAttributes.Add("value", "My Value");
我相信如果你简单地添加 value
I believe that if you simply add the value
attribute to the markup, this will also get populated.
您可以访问该值:
myChk.InputAttributes["value"];
要回答 / em> 价值
不是 CheckBox
控件的内置属性:
To answer the question of why Value
is not a build in attribute to the CheckBox
control:
A CheckBox
在隔离(只是其本身)不需要任何值。根据定义,它是一个布尔值,由其ID标识。
A CheckBox
in isolation (just by itself) needs no value. By definition it is a boolean and is identified by its ID. All you need to do is check whether it was checked or not.
当您群组核取方块并且有控制项时,该值就会起作用为此 - CheckBoxList
使用 ListItem
- 每个 ListItem
有 Value
属性。
The value comes into play when you group checkboxes and there is a control for that - the CheckBoxList
that uses ListItem
- each ListItem
does have a Value
property.
这篇关于为什么我不能在asp:复选框上设置值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!