<td colspan="2"><input id="T11" name="T1" type="radio" style="vertical-align:middle"/>比自己更强的</td>
<td colspan="2"><input id="T12" name="T1" type="radio" style="vertical-align:middle"/>尊敬自己的</td>
</tr><label>学生</label><input type="radio" checked="checked" name="identype" value="student" />
<label>教师</label><input type="radio" name="identype" value="teacher" />
<label>管理员</label><input type="radio" name="identype" value="admin" />
--------------------------------------------------------------------------------------------
然後提交的时候,根据name是“identype”来获取用户选择的是哪个。
String indentity = (String)requestgetParameter("identype");
if(indentity != null && !indentityequals("")){
if(indentityequals(“student”)){
//如果是学生身份处理代码
}else if(indentityequals("teacher")){
//如果是老师身份
}else if(indentityequals("admin")){
//如果是其他身份
}
}测试控件的
Checked
属性。
注意
测试单选按钮的值并不能告诉您用户是否更改了该控件的值,而只能告诉您该控件是否已选中。
若要检查控件中的更改,请为控件的
CheckedChanged
事件编写事件处理程序。
有关详细信息,请参见
如何:响应
RadioButton
组中的用户选择。
若要确定一组中哪个控件被选中,必须分别测试每个控件,如下面的代码示例所示。
Protected
Sub
Button1_Click(ByVal
sender
As
Object,
_
ByVal
e
As
SystemEventArgs)
Handles
Button1Click
Dim
msg
As
String
=
"You
selected
"
If
RadioButton1Checked
=
True
Then
msg
=
msg
&
RadioButton1Text
ElseIf
Radiobutton2Checked
=
True
Then
msg
=
msg
&
RadioButton2Text
ElseIf
Radiobutton3Checked
=
True
Then
msg
=
msg
&
RadioButton3Text
End
If
Label1Text
=
msg
End
Subpublic
void
Button1_Click
(object
sender,
SystemEventArgs
e)
{
if
(RadioButton1Checked)
{
Label1Text
=
"You
selected
"
+
RadioButton1Text;
}
else
if
(RadioButton2Checked)
{
Label1Text
=
"You
selected
"
+
RadioButton2Text;
}
else
if
(RadioButton3Checked)
{
Label1Text
=
"You
selected
"
+
RadioButton3Text;
}
} [documentquerySelectorAll("input[name=ifLvzhou]")]forEach((item) => {
if (itemvalue === "否") {
itemchecked = true;
}
});
请采纳
radiobox是aspnet中的web服务器控件,是单选按钮框(圆形的那种)相当于Html中的radiobutton。你可以使用radioboxlist来实现你想要的单选。
前台:
<asp:RadioBoxList ID="rblSex" Runat="server">
<ItemTemplate>
男
</ItemTemplate>
<ItemTemplate>
女
</ItemTemplate>
</asp:RadioBoxList>
(手写的不知道有没有写错,你可以去vs里面拉出来试试,就这个意思)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)