如何控制gridview中的checkbox只能有一个被选中??
<asp:GridView ID= "gridShow " runat= "server " Height= "129px " Width= "584px " OnDataBound= "gridShow_DataBound " OnRowDataBound= "gridShow_RowDataBound " AutoGenerateColumns= "False " OnSelectedIndexChanged= "gridShow_SelectedIndexChanged ">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID= "CustomerID " runat= "server " />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField= "CustomerID " HeaderText= "CustomerID " />
<asp:BoundField DataField= "CompanyName " HeaderText= "CompanyName " />
<asp:BoundField DataField= "ContactName " HeaderText= "ContactName " />
<asp:BoundField DataField= "ContactTitle " HeaderText= "ContactTitle " />
<asp:BoundField DataField= "Address " HeaderText= "Address " />
</Columns>
</asp:GridView>
------解决方案--------------------int j = 0;
for(int i = 0; i < dg.Items.Count; i++)
{
if((dg.Items[i].Cells[0].FindControl( "chkID ") as CheckBox).Checked)
{
j++;
}
if(j > 1)
{
MessageBox.Show(this, "只能选一个! ");
break;
}
}
------解决方案--------------------我会用jquery来做,纯javascript不会
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<title> 无标题页 </title>
<script type= "text/jscript " language= "javascript " src= "jquery-latest.pack.js "> </script>
<script langua