方法1:如果你只是想唯一选中,不触发任何事件:你可以用前台控件<input id = "select" type = "radio" />
方法2:Gridview中的radio用服务器控件
后台:this._offerCounties.Attributes.Add("onclick", "postBackByObject()");
前台代码:
<script language="javascript">
function postBackByObject()
{
var element = window.event.srcElement;
if (element.tagName == "INPUT" && element.type == "checkbox")
{
var checkedState = element.checked;
while (element.tagName != "TABLE")
element = element.parentElement;
UnCheck(element);
element = element.nextSibling;
if (element == null)
return;
var childTables = element.getElementsByTagName("TABLE");
for (var tableIndex = 0; tableIndex < childTables.length; tableIndex++)
Check(childTables[tableIndex], checkedState);
}
}
function UnCheck(table)
{
if (table == null || table.rows[0].cells.length == 2) // This is the root
return;
var parentTable = table.parentElement.previousSibling;
Check(parentTable, false);
UnCheck(parentTable);
}
function Check(table, checked)
{
var checkboxIndex = table.rows[0].cells.length - 1;
var cell = table.rows[0].cells[checkboxIndex];
var checkboxes = cell.getElementsByTagName("INPUT");
if (checkboxes.length == 1)
checkboxes[0].checked = checked;
}
</script>
来源:https://www.cnblogs.com/Niko-zhuang/archive/2008/09/27/1299958.html