189 8069 5689

C#中怎么利用CheckBox实现单选功能

今天就跟大家聊聊有关C# 中怎么利用CheckBox实现单选功能,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

站在用户的角度思考问题,与客户深入沟通,找到瓦房店网站设计与瓦房店网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:成都网站制作、成都做网站、企业官网、英文网站、手机端网站、网站推广、域名注册、网页空间、企业邮箱。业务覆盖瓦房店地区。

DataGrid中加入CheckBox,并实现c# CheckBox单选原理就是用js遍列所有CheckBox把所有CheckBox设为未被选中,然后在把单击的CheckBox设为选中。

aspx文件:

<%@ page language="c#" codebehind="webform1.aspx.cs" autoeventwireup="false" inherits="datagridcheck.webform1" %>            webform1title>   <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></pre><p>以下是cs文件</p><pre>using system;   using system.collections;   using system.componentmodel;   using system.data;   using system.drawing;   using system.web;   using system.web.sessionstate;   using system.web.ui;   using system.web.ui.webcontrols;   using system.web.ui.htmlcontrols;   namespace datagridcheck   {   /// <summary>   /// webform1 的摘要说明。   /// summary>   public class webform1 : system.web.ui.page   {   protected system.web.ui.webcontrols.button button1;   protected system.web.ui.webcontrols.datagrid dg;   private void page_load(object sender, system.eventargs e)   {   // 在此处放置用户代码以初始化页面   if (!page.ispostback)   {   dg.datasource= createdatasource() ;   dg.databind();   }   }   icollection createdatasource()   {   datatable dt = new datatable();   datarow dr;   dt.columns.add(new datacolumn("integervalue", typeof(int32)));   dt.columns.add(new datacolumn("stringvalue", typeof(string)));   dt.columns.add(new datacolumn("currencyvalue", typeof(double)));   for (int i = 0; i < 9; i++)   {   dr = dt.newrow();   dr[0] = i;   dr[1] = "item " + i.tostring();   dr[2] = 1.23 * (i + 1);   dt.rows.add(dr);   }   dataview dv = new dataview(dt);   return dv;   }   #region web 窗体设计器生成的代码   override protected void oninit(eventargs e)   {   //   // codegen: 该调用是 asp.net web 窗体设计器所必需的。   //   initializecomponent();   base.oninit(e);   }   /// <summary>   /// 设计器支持所需的方法 - 不要使用代码编辑器修改   /// 此方法的内容。   /// summary>   private void initializecomponent()   {   this.dg.itemdatabound += new system.web.ui.webcontrols.datagriditemeventhandler(this.dg_itemdatabound);   this.button1.click += new system.eventhandler(this.button1_click);   this.load += new system.eventhandler(this.page_load);   }   #endregion   private void button1_click(object sender, system.eventargs e)   {   system.web.ui.webcontrols.checkbox chkexport;   foreach (datagriditem dgitem in dg.items)   {   chkexport=(checkbox)dgitem.findcontrol("chkexport");   if(chkexport.checked)   {   response.write("<script>alert("+dgitem.cells[2].text+"和"+dgitem.cells[3].text+")script>");   }   }   }   private void dg_itemdatabound(object sender, system.web.ui.webcontrols.datagriditemeventargs e)   {   if(e.item.itemindex<0) return;   if(e.item.itemtype == listitemtype.item || e.item.itemtype == listitemtype.alternatingitem)   {   system.web.ui.webcontrols.checkbox chkexport;   chkexport=(checkbox)e.item.findcontrol("chkexport");   chkexport.attributes.add("onclick","setcheckboxstate()");   e.item.attributes.add("onmouseover","currentcolor=this.style.backgroundcolor;this.style.backgroundcolor=48d1cc");   e.item.attributes.add("onmouseout","this.style.backgroundcolor=currentcolor");  }   }   }   }</pre><p>看完上述内容,你们对C# 中怎么利用CheckBox实现单选功能有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。</p>            
            
                        <br>
            网站标题:C#中怎么利用CheckBox实现单选功能            <br>
            网站路径:<a href="http://cdxtjz.cn/article/jhiish.html">http://cdxtjz.cn/article/jhiish.html</a>
        </div>
    </div>
    <div class="other">
        <h3>其他资讯</h3>
        <ul>
            <li>
                    <a href="/article/ddjdjos.html">有空间域名怎么建网站 空间域名什么意思</a>
                </li><li>
                    <a href="/article/ddjdjce.html">国产服务器安全性高吗 国产服务器cpu有哪些</a>
                </li><li>
                    <a href="/article/ddjdjss.html">linux自动化执行命令 linux 自动化</a>
                </li><li>
                    <a href="/article/ddjdjsh.html">c语言用函数写华氏温度 c语言计算华氏温度100℃对应的摄氏温度</a>
                </li><li>
                    <a href="/article/ddjdjco.html">智能聊天一定需要注册吗 chatroulette需要登录</a>
                </li>        </ul>
    </div>
</div>
<footer>
  <div class="foot container">
    <div class="footl fl">
      <h3>联系我们</h3>
      <dl>
        您好HELLO!<br>
        感谢您来到成都网站建设公司,若您有合作意向,请您为我们留言或使用以下方式联系我们,

        我们将尽快给你回复,并为您提供真诚的设计服务,谢谢。
      </dl>
      <ul>
        <li>电话:028- <span>86922220 18980695689</span></li>
        <li>商务合作邮箱:631063699@qq.com</li>
        <li>合作QQ: 532337155</li>
        <li>成都网站设计地址:成都市青羊区锣锅巷31号五金站写字楼6楼</li>
      </ul>
    </div>
    <div class="footr fr">
      <h3>小谭建站工作室</h3>
      <dl>
        成都小谭网站建设公司拥有多年以上互联网从业经验的团队,始终保持务实的风格,以"帮助客户成功"为已任,专注于提供对客户有价值的服务。

        我们已为众企业及上市公司提供专业的网站建设服务。我们不只是一家网站建设的网络公司;我们对营销、技术、管理都有自己独特见解,小谭建站采取“创意+综合+营销”一体化的方式为您提供更专业的服务!
      </dl>
      <h3>小谭观点</h3>
      <dl>
        相对传统的成都网站建设公司而言,小谭是互联网中的网站品牌策划,我们精于企业品牌与互联网相结合的整体战略服务。<br>
        我们始终认为,网站必须注入企业基因,真正使网站成为企业vi的一部分,让整个网站品牌策划体系变的深入而持久。
      </dl>
    </div>
  </div>
  <div class="link">
    <div class="container"> 
        <span> 友情链接:</span>
        <a href="http://www.cqcxhl.com/" title="重庆做网站" target="_blank">重庆做网站</a>   <a href="http://www.kswsj.cn/tuiguang/" title="网站SEO优化排名" target="_blank">网站SEO优化排名</a>   <a href="http://www.hdybtv.com/" title="造型师设计" target="_blank">造型师设计</a>   <a href="http://www.cdkjz.cn/wangzhan/" title="网络推广公司" target="_blank">网络推广公司</a>   <a href="http://chengdu.cdcxhl.com/weixin/" title="微信开发" target="_blank">微信开发</a>   <a href="http://www.cqcxhl.com/service/" title="高端网站定制" target="_blank">高端网站定制</a>   <a href="http://www.myzitong.com/" title="梓潼网站设计" target="_blank">梓潼网站设计</a>   <a href="http://www.cdhuace.com/vi.html" title="vi形象设计" target="_blank">vi形象设计</a>   <a href="http://seo.cdkjz.cn/mobile/" title="手机网站建设" target="_blank">手机网站建设</a>   <a href="http://www.gxwzsj.com/" title="广西弘博建站" target="_blank">广西弘博建站</a>     
    </div>
  </div>
  <div class="copy"> © Copyright 2023 <a href="http://www.cdxtjz.cn/">小谭建站工作室</a>All Rights Reserved.  <a href="https://www.cdxwcx.com" target="_blank">成都网站建设</a> / <a href="https://www.cdcxhl.com/" target="_blank">成都网站建设</a> / <a href="https://www.cdxwcx.com" target="_blank">响应式网站建设</a> / <a href="https://www.cdcxhl.com/zuyong/" target=" _blank">成都服务器租用</a></div>
</footer>
</body>
</html>
<script>
    $(".con img").each(function(){
        var src = $(this).attr("src");    //获取图片地址
        var str=new RegExp("http");
        var result=str.test(src);
        if(result==false){
            var url = "https://www.cdcxhl.com"+src;    //绝对路径
            $(this).attr("src",url);
        }
    });
    window.onload=function(){
        document.oncontextmenu=function(){
            return false;
        }
    }
</script>