网站建设资讯

NEWS

网站建设资讯

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://cdweb.net/article/jhiish.html">http://cdweb.net/article/jhiish.html</a>
        </div>
    </div>
    <div class="other">
        <h3>其他资讯</h3>
        <ul>
            <li>
                    <a href="/article/pdioij.html">什么是ink域名</a>
                </li><li>
                    <a href="/article/pdiogg.html">误删除mysql数据库表该如何恢复操作方法</a>
                </li><li>
                    <a href="/article/pdiooh.html">node链接mongodb数据库的方法详解【阿里云服务器环境ubuntu】</a>
                </li><li>
                    <a href="/article/pdiocj.html">docker容器挂了怎么办</a>
                </li><li>
                    <a href="/article/pdehhi.html">macOS上,实现Wireshark手机抓包</a>
                </li>        </ul>
    </div>
</div>
</div>
<footer>
    <div class="footop">
        <div class="wrap">
            <div class="bottomrpw">
                <div class="erp arp">
                    <dl>
                        <dt>ADDRESS</dt>
                        <dd class="address"> <i class="icon"></i> <span class="word">成都市青羊区锦天国际1号楼1002室</span> </dd>
                    </dl>
                </div>
                <div class="erp arp">
                    <dl>
                        <dt>TEL</dt>
                        <dd class="phonum"> <i class="icon"></i> <span class="word en"> <a href="tel:18980820575">18980820575</a> </span> </dd>
                    </dl>
                </div>
                <div class="erp crp">
                    <dl>
                        <dt>OTHER</dt>
                        <dd> <a class="word get-quote">获得报价与方案</a> </dd>
                        <dd> <a href="#" target="_blank" rel='nofollow' class="word" title="付款方式">付款方式</a> </dd>
                    </dl>
                </div>
                <div class="erp code-rp">
                    <dl>
                        <dt>Wechat</dt>
                        <dd class="code-wrap"> <span class="code"> <img src="/Public/Home/images/qr-code.jpg" alt="快上网微信公众号" /> </span> </dd>
                    </dl>
                </div>
            </div>
        </div>
    </div>
    <div class="footerbot">
        <div class="friendlinks">
            <div class="wrap">
                <ul class="rpl">
                    <li><a href="http://chengdu.cdcxhl.cn/jianshe/" title="网站建设公司" target="_blank">网站建设公司</a></li><li><a href="http://www.cdhuace.com/fuwu.html" title="名片印刷" target="_blank">名片印刷</a></li><li><a href="http://www.xhgfhy.com/
" title="犀浦封阳台" target="_blank">犀浦封阳台</a></li><li><a href="http://www.cdxwcx.cn/tuoguan/dazhou.html" title="达州托管服务器" target="_blank">达州托管服务器</a></li><li><a href="https://www.cdxwcx.com/400/" title="成都400电话" target="_blank">成都400电话</a></li><li><a href="https://www.cdxwcx.com/jifang/xiyun.html" title="成都移动机房" target="_blank">成都移动机房</a></li><li><a href="http://www.idckuai.cn/" title="注册域名" target="_blank">注册域名</a></li><li><a href="https://www.cdcxhl.com/mianfei/jianshe/chengdu.html" title="成都免费网站建设" target="_blank">成都免费网站建设</a></li><li><a href="http://www.dcwzsj.com/" title="德昌麦琪建站" target="_blank">德昌麦琪建站</a></li><li><a href="http://www.cdkjz.cn/wangzhan/menhu/" title="成都门户网站建设" target="_blank">成都门户网站建设</a></li>                </ul>
            </div>
        </div>
        <div class="wrap">
            <div class="copyright"> <span class="en">©2007-2022</span> 成都快上网科技有限公司 <span class="en">ALL RIGHTS
                        RESERVED.</span> <a rel="nofollow" href="http://www.miitbeian.gov.cn" target="_blank">蜀ICP备19037934号</a> </div>
        </div>
    </div>
</footer>
<div class="fcwrap">
    <ul class="rpl clearfix">
        <li class="phone"> <a rel="nofollow" target="_blank" href="tel:18980820575"> <i class="icon"></i>
            <strong>18980820575</strong> </a> </li>
        <li class="qq"> <a rel="nofollow" target="_blank"
                           href="https://wpa.qq.com/msgrd?v=1&uin=244261566&site=qq&menu=yes"> <i class="icon"></i>
            <strong>244261566</strong> </a> </li>
        <li class="back-top"> <a href="javascript:void(0)" rel="nofollow" class="back-to-top"> <i class="icon"></i>
            <strong>回到顶部</strong> </a> </li>
    </ul>
</div>
<!--nav-->
<div class="n-Wrap">
    <div class="navBar visble show">
        <div class="barlogo">
            <a href="/" rel="nofollow">
                <img src="/Public/Home/images/logo1.png" alt="成都做网站" />
                <img src="/Public/Home/images/logo2.png" alt="成都网站设计" />
            </a>
        </div>
        <div class="bmenu">
            <i class="bar-top"><span></span></i>
            <i class="bar-cen"><span></span></i>
            <i class="bar-bom"><span></span></i>
            <i class="bar-left"><span></span></i>
            <i class="bar-right"><span></span></i>
        </div>
    </div>
    <section class="fixmenu">
        <div class="close-bar">
            <i class="bar-left"><span></span></i>
            <i class="bar-right"><span></span></i>
        </div>
        <nav class="smph">
            <ul>
                <li class="index-hrefs on"><a href="http://www.cdweb.net/"><font>首页</font></a></li>
                <li><a href="/about/" rel="nofollow"><font>关于快上网</font></a></li>
                <li><a href="/service/" rel="nofollow"><font>服务范围</font></a></li>
                <li><a href="/case/" rel="nofollow"><font>案例展示</font></a></li>
                <li><a href="/solve/" rel="nofollow"><font>解决方案</font></a></li>
                <li><a href="/news/" rel="nofollow"><font>建站资讯</font></a></li>
                <li><a href="/contact/" rel="nofollow"><font>联系快上网</font></a></li>
            </ul>
            <div class="pwrap">
                <span class="label">服务热线</span>
                <strong class="phone"><a href="tel:18980820575">18980820575</a></strong>
            </div>
        </nav>
    </section>
</div>
<!--end nav-->
<script src="/Public/Home/js/hotcss.js"></script>
<script type="text/javascript" src="/Public/Home/js/su_new.js"></script>
</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>