两个数据与单选按钮在一个aspx页面
本文关键字:页面 一个 aspx 两个 数据 单选按钮 | 更新日期: 2023-09-27 17:50:57
我有两个数据在一个aspx页面。我需要确保只有一个单选按钮可以为每个数据选择。但是,我只能对两个数据表执行此操作,这意味着当我单击datalist1上的单选按钮时,当我在datalist2上选择另一个单选按钮时,它只允许我选择一个单选按钮。我需要确保当我在datalist1上选择一个单选按钮时,我也能够在datalist2上选择另一个单选按钮。
有人能帮帮我吗?
下面是javascript在aspx中的页面。
<script type="text/javascript" language="javascript">
function CheckOnes(spanChk) {
var oItem = spanChk.children;
var theBox = (spanChk.type == "radio")
spanChk : spanChk.children.item[0];
xState = theBox.unchecked;
elm = theBox.form.elements;
for (i = 0; i < elm.length; i++)
if (elm[i].type == "radio" && elm[i].id != theBox.id) {
elm[i].checked = xState;
}
}
function CheckTwos(spanChk2) {
var oItem2 = spanChk2.children;
var theBox2 = (spanChk2.type == "radio")
spanChk2 : spanChk2.children.item[0];
xState2 = theBox2.unchecked;
elm2 = theBox2.form.elements;
for (i = 0; i < elm2.length; i++)
if (elm2[i].type == "radio" && elm2[i].id != theBox2.id) {
elm2[i].checked = xState2;
}
}
下面是asp .cs
中的代码protected void DataList2_ItemDataBound(object sender, DataListItemEventArgs e)
{
RadioButton rdb;
rdb = (RadioButton)e.Item.FindControl("radioDelete");
if (rdb != null)
rdb.Attributes.Add("onclick", "CheckTwos(this);");
}
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
RadioButton rdb;
rdb = (RadioButton)e.Item.FindControl("radioAdd");
if (rdb != null)
rdb.Attributes.Add("onclick", "CheckOnes(this);");
}
您只需要让任何一组单选按钮具有相同的名称。
Group1 :
<input type="radio" name="group1" />
<input type="radio" name="group1" />
Group2 :
<input type="radio" name="group2" />
<input type="radio" name="group2" />
Group3 :
<input type="radio" name="group3" />
<input type="radio" name="group3" />