62,267
社区成员
发帖
与我相关
我的任务
分享
<Columns>
<asp:BoundColumn DataField="CheckCode" HeaderText="编号"> </asp:BoundColumn>
<asp:BoundColumn DataField="CheckItem" HeaderText="检查项目">
<ItemStyle Width="80px" />
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="结 果" ItemStyle-Width = "70">
<ItemTemplate>
<input id="SelectedID" runat="server" type="hidden" value=' <%# DataBinder.Eval(Container.DataItem, "CheckCode")%>' />
<asp:CheckBoxList ID="ItemCheckResult" runat="server" Font-Names="宋体" Font-Size="10pt" Height="1px" RepeatDirection="Vertical" >
<asp:ListItem>合格 </asp:ListItem>
<asp:ListItem>不合格 </asp:ListItem>
</asp:CheckBoxList>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" Width="50px" Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" />
</asp:TemplateColumn>
</Columns>
<script>
addClickEvent('<%=DG_Data.ClientID %>',0);
</script>
<script>
function singleChecked(obj)
{
var input=obj.getElementsByTagName('input');
for(var i=0;i<input.length;i++)
{
if((input[i].type='checkbox')&&(input[i].id!=event.srcElement.id))
document.getElementById(input[i].id).checked=false;
}
}
function addClickEvent(id,colIndex)
{
var table=document.getElementById(id);
if(table)
{
var tempID;
for(var i=1;i<table.rows.length;i++)
{
var input=table.rows[i].cells[colIndex].getElementsByTagName('input');
tempID=table.rows[i].cells[colIndex].childNodes[0].id;
for(var j=0;j<input.length;j++)
{
if(input[j].type='checkbox')
{
(function(){
var tb=document.getElementById(tempID);//每个闭包使用不同的变量
input[j].onclick = function(){singleChecked(tb);};
})();
}
}
}
}
else
return;
}
</script>
<script>
addClickEvent('<%=gv.ClientID %>',0);
</script>
var pid = this.parentNode.parentNode.parentNode.parentNode.id;
function eforCheck(gridID,checkListID){
var objs = {};
var grid = document.getElementById(gridID);
if(grid==null) return;
var tables = grid.getElementsByTagName("table");
for(var i=0;i<tables.length;i++){
if(tables[i].id.indexOf(checkListID)!=-1){
objs[tables[i].id] = null;
var chks = document.getElementById(tables[i].id).getElementsByTagName("input");
for(var j=0;j<chks.length;j++){
chks[j].onclick=function(){
if(this.checked){
var pid = this.parentNode.parentNode.parentNode.parentNode.id;
if(objs[pid]!=null && objs[pid]!=this){
objs[pid].checked=false;
objs[pid] = null;
}
objs[pid] = this;
}
};
}
}
}
}<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>无标题页</title>
<script language="javascript">
function eforCheck(gridID,checkListID){
var obj = null;
var grid = document.getElementById(gridID);
if(grid==null) return;
var tables = grid.getElementsByTagName("table");
for(var i=0;i<tables.length;i++){
if(tables[i].id.indexOf(checkListID)!=-1){
var chks = document.getElementById(tables[i].id).getElementsByTagName("input");
for(var j=0;j<chks.length;j++){
chks[j].onclick=function(){
if(this.checked){
if(obj!=null && obj!=this)obj.checked=false;
obj = this;
}
};
}
}
}
}
window.onload=function(){
eforCheck("<%=DG_Data.ClientID%>","ItemCheckResult");
};
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:DataGrid ID="DG_Data" runat="server">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<input id="SelectedID" runat="server" type="hidden" />
<asp:CheckBoxList ID="ItemCheckResult" runat="server" Font-Names="宋体" Font-Size="10pt"
Height="1px" RepeatDirection="Vertical" >
<asp:ListItem>合格 </asp:ListItem>
<asp:ListItem>不合格 </asp:ListItem>
<asp:ListItem>优秀 </asp:ListItem>
</asp:CheckBoxList>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</html>
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("a", typeof(string)));
dt.Rows.Add(1);
dt.Rows.Add(2);
dt.Rows.Add(3);
DG_Data.DataSource = dt;
DG_Data.DataBind();
}
<script>
function singleChecked()
{
var p=event.srcElement.parentNode;
var input=p.getElementsByTagName('input');
for(var i=0;i<input.length;i++)
{
if((input[i].type='checkbox')&&(input[i].id!=event.srcElement.id))
document.getElementById(input[i].id).checked=false;
}
}
</script>
<asp:GridView ID="gv" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="ckbOne" Text="合格" runat="server" onclick="singleChecked();" />
<asp:CheckBox ID="ckbTwo" Text="不合格" runat="server" onclick="singleChecked();" />
<asp:CheckBox ID="ckbThree" Text="优秀" runat="server" onclick="singleChecked();" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script language="javascript">
function eforCheck(gridID,checkListID){
var obj = null;
var grid = document.getElementById(gridID);
if(grid==null) return;
var tables = grid.getElementsByTagName("table");
for(var i=0;i<tables.length;i++){
if(tables[i].id.indexOf(checkListID)!=-1){
var chks = document.getElementById(tables[i].id).getElementsByTagName("input");
for(var j=0;j<chks.length;j++){
chks[j].onclick=function(){
if(this.checked){
if(obj!=null && obj!=this)obj.checked=false;
obj = this;
}
};
}
}
}
}
window.onload=function(){
eforCheck("<%=DG_Data.ClientID%>","ItemCheckResult");
};
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:DataGrid ID="DG_Data" runat="server" OnLoad="DG_Data_Load">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBoxList ID="ItemCheckResult" runat="server" Font-Names="宋体" Font-Size="10pt"
Height="1px" RepeatDirection="Vertical" >
<asp:ListItem>合格 </asp:ListItem>
<asp:ListItem>不合格 </asp:ListItem>
<asp:ListItem>优秀 </asp:ListItem>
</asp:CheckBoxList>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</html><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script language="javascript">
window.onload = function(){
var obj = null;
var chks = document.getElementById("<%=ItemCheckResult.ClientID %>").getElementsByTagName("input");
for(var i=0;i<chks.length;i++){
chks[i].onclick=function(){
if(this.checked){
if(obj!=null && obj!=this)obj.checked=false;
obj = this;
}
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:CheckBoxList ID="ItemCheckResult" runat="server" Font-Names="宋体" Font-Size="10pt"
Height="1px" RepeatDirection="Vertical" >
<asp:ListItem>合格 </asp:ListItem>
<asp:ListItem>不合格 </asp:ListItem>
<asp:ListItem>优秀 </asp:ListItem>
</asp:CheckBoxList>
</form>
</body>
</html>