首页 > 编程 > .NET > 正文

在DataGrid中加入CheckBox实现单选

2024-07-10 12:38:02
字体:
来源:转载
供稿:网友

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="DataGridCheck.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
 <HEAD>
  <title>WebForm1</title>
  <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
  <meta content="C#" name="CODE_LANGUAGE">
  <meta content="JavaScript" name="vs_defaultClientScript">
  <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
  <SCRIPT language="JavaScript">
     function SetCheckBoxState()
     {
     var dom=document.all;
     var el=event.srcElement;
        if(el.tagName=="INPUT"&&el.type.toLowerCase()=="checkbox")
     {
  for(i=0;i<dom.length;i++)
  {
      if(dom[i].tagName=="INPUT"&&dom[i].type.toLowerCase()=="checkbox")
      {
   dom[i].checked=false;
      }
  }
     }
     el.checked=!el.checked;
        }
  </SCRIPT>
 </HEAD>
 <body MS_POSITIONING="GridLayout">
  <form id="Form1" method="post" runat="server">
   <FONT face="宋体">
    <asp:datagrid id="dg" style="Z-INDEX: 101; LEFT: 168px; POSITION: absolute; TOP: 40px" runat="server"
     Width="440px" AutoGenerateColumns="False">
     <Columns>
      <asp:TemplateColumn>
       <ItemTemplate>
        <asp:CheckBox id="chkExport" runat="server"></asp:CheckBox>
       </ItemTemplate>
      </asp:TemplateColumn>
      <asp:BoundColumn DataField="IntegerValue"></asp:BoundColumn>
      <asp:BoundColumn DataField="StringValue"></asp:BoundColumn>
      <asp:BoundColumn DataField="CurrencyValue"></asp:BoundColumn>
     </Columns>
    </asp:datagrid><asp:button id="Button1" style="Z-INDEX: 102; LEFT: 168px; POSITION: absolute; TOP: 8px" runat="server"
     Text="显示内容"></asp:button></FONT></form>
 </body>
</HTML>

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表