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://csdahua.cn/article/jhiish.html">http://csdahua.cn/article/jhiish.html</a>
                </div>
                <div class="view-qrocde cl">
                    <div class="m z"><img src="/Public/Home/images/ew.jpg"/></div>
                    <div class="text">
                        <h6>扫二维码与项目经理沟通</h6>
                        <p>我们在微信上24小时期待你的声音</p>
                        <p>解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流</p>
                    </div>
                </div>
                <div class="othernews cl">
                    <h3>其他资讯</h3>
                    <ul>
                        <li><a href="/article/cihiis.html">dns服务器是什么?dns服务器运作流程是什么?</a></li><li><a href="/article/cihipe.html">域名被盗怎样找回?有哪些方法?</a></li><li><a href="/article/cihiph.html">.gov域名申请要求有哪些?需要什么材料?</a></li><li><a href="/article/cihgoj.html">域名是什么?常用域名一般都有哪些?</a></li><li><a href="/article/cihijo.html">自动获取dns的最新操作流程介绍</a></li>                    </ul>
                </div>
            </div>
        </div>
        <div class="sidebar">
            <div class="tuijian">
                <a href="#">
                    <h2 class="cl"><span>行业动态</span></h2>
                    <h3>企业网站建设的重要性!</h3>
                    <p>现在虽然是移动互联网时代,但企业网站依然重要,包含PC站点,移动站。可以说企业网站关系企业的未来发展和前途,尤其对中小企业更是如此,一些中小企业老板,对自己的名片很在乎,因为这是个门面。...</p>
                </a>
            </div>
            <div class="ser sidesub">
                <h2>服务项目</h2>
                <ul class="ebox">
                    <li class="sub sub-1">
                        <div>
                            <h3>网站建设</h3>
                            <p></p>
                            <a class="btn" href="/serve/website/">查看详情</a>
                        </div>
                    </li>
                    <li class="sub sub-1">
                        <div>
                            <h3>移动端/APP</h3>
                            <p></p>
                            <a class="btn" href="/serve/moblie/">查看详情</a>
                        </div>
                    </li>
                    <li class="sub sub-1">
                        <div>
                            <h3>微信/小程序</h3>
                            <p></p>
                            <a class="btn" href="/serve/small/">查看详情</a>
                        </div>
                    </li>
                    <li class="sub sub-1">
                        <div>
                            <h3>技术支持</h3>
                            <p></p>
                            <a class="btn" href="/serve/tech/">查看详情</a>
                        </div>
                    </li>
                    <li class="sub sub-1">
                        <div>
                            <h3>其它服务</h3>
                            <p></p>
                            <a class="btn" href="/serve/othe/">查看详情</a>
                        </div>
                    </li>
                    <li class="sub sub-5">
                        <div>
                            <h3>更多服务项目</h3>
                            <p> <a>用我们的专业和诚信赢得您的信赖,从PC到移动互联网均有您想要的服务!</a></p>
                            <a class="btn" href="/serve/">获取更多</a>
                        </div>
                    </li>
                </ul>
            </div>
            <div class="contact" id="fix">
                <h2 class="cl"> <span>联系吧</span> <a href="https://map.baidu.com/" class="ditu" rel="nofollow" target="_blank">在百度地图上找到我们</a> </h2>
                <h3>电话:13518219792</h3>
                <p>如遇占线或暂未接听请拨:136xxx98888</p>
                <div class="qq"> <a href="//wpa.qq.com/msgrd?v=3&uin=244261566&site=qq&menu=yes" rel="nofollow" target="_blank">业务咨询</a> <a href="//wpa.qq.com/msgrd?v=3&uin=244261566&site=qq&menu=yes" rel="nofollow" target="_blank">技术咨询</a> <a href="//wpa.qq.com/msgrd?v=3&uin=244261566&site=qq&menu=yes" rel="nofollow" target="_blank">售后服务</a> </div>
            </div>
        </div>
        <script>
            //固定滚动
            (function () {
                var oDiv = document.getElementById("fix");
                var H = 120,
                    iE6;
                var Y = oDiv;
                while (Y) {
                    H += Y.offsetTop;
                    Y = Y.offsetParent
                };
                iE6 = window.ActiveXObject && !window.XMLHttpRequest;
                if (!iE6) {
                    window.onscroll = function ()
                    {
                        var s = document.body.scrollTop || document.documentElement.scrollTop;
                        if (s > H) {
                            oDiv.className = "contact  fixed";
                            if (iE6) {
                                oDiv.style.top = (s - H) + "px";
                            }
                        } else {
                            oDiv.className = "contact ";
                        }
                    };
                }

            })();
        </script>
    </div>
    <div class="footer">
        <div class="wp">
            <div class="wpss cl">
                <dl class="about">
                    <dt>网站制作</dt>
                    <dd><a href="http://chengdu.cdcxhl.com/" target="_blank" title="成都网站制作">成都网站制作</a></dd><dd><a href="http://m.xwcx.net/" target="_blank" title="H5网站制作">H5网站制作</a></dd><dd><a href="http://www.cdxwcx.cn/" target="_blank" title="成都网站制作公司">成都网站制作公司</a></dd><dd><a href="http://chengdu.xwcx.net/mobile/" target="_blank" title="移动手机网站制作">移动手机网站制作</a></dd>                </dl>
                <dl class="about">
                    <dt>网站建设</dt>
                    <dd><a href="http://www.cdkjz.cn/" target="_blank" title="网站建设">网站建设</a></dd><dd><a href="http://www.scjiangyou.cn/" target="_blank" title="江油网站建设">江油网站建设</a></dd><dd><a href="http://www.sclezhi.cn/" target="_blank" title="乐至网站建设">乐至网站建设</a></dd><dd><a href="https://www.cdcxhl.com/xiangyingshi.html" target="_blank" title="成都响应式网站建设">成都响应式网站建设</a></dd>                </dl>
                <dl class="about">
                    <dt>网站设计</dt>
                    <dd><a href="http://www.cqcxhl.com/" target="_blank" title="网站设计">网站设计</a></dd><dd><a href="http://www.cdxwcx.cn/" target="_blank" title="成都网站设计">成都网站设计</a></dd><dd><a href="http://chengdu.cdcxhl.cn/dingzhi/" target="_blank" title="定制网站设计">定制网站设计</a></dd><dd><a href="http://chengdu.cdcxhl.cn/H5/" target="_blank" title="响应式网站设计">响应式网站设计</a></dd>                </dl>
                <dl class="contact">
                    <dt>联系我们</dt>
                    <dd>电话:13518219792</dd>
                    <dd>邮箱:631063699@qq.com</dd>
                    <dd>地址:成都青羊区锦天国际1002号</dd>
                    <dd>网址:www.csdahua.cn</dd>
                </dl>
                <dl class="flow">
                    <dt></dt>
                    <div class="ma cl">
                        <div class="m"> <img src="/Public/Home/images/ew.jpg" />
                            <p>微信二维码</p>
                        </div>
                    </div>
                </dl>
            </div>
        </div>
        <div class="footer-link wp">
            <ul class="wpss cl">
                <li class="fisrt">友情链接</li>
                <li><a href="http://www.cdxwcx.cn/tuoguan/sichuan.html" title="四川服务器托管" target="_blank">四川服务器托管</a></li><li><a href="http://www.cdxwcx.cn/tuoguan/zigong.html" title="自贡电信机房" target="_blank">自贡电信机房</a></li><li><a href="http://seo.cdkjz.cn/quanwang/" title="全网营销" target="_blank">全网营销</a></li><li><a href="http://www.cxjianzhan.com/mobile/" title="wap网站制作" target="_blank">wap网站制作</a></li><li><a href="http://chengdu.cdxwcx.cn/wangzhan/" title="手机网站制作" target="_blank">手机网站制作</a></li><li><a href="http://www.wjwzjz.com/" title="温江做网站公司" target="_blank">温江做网站公司</a></li><li><a href="http://www.cdxwcx.cn/tuoguan/yaan.html" title="雅安服务器托管" target="_blank">雅安服务器托管</a></li><li><a href="http://www.kswcd.com/solution/" title="网站方案" target="_blank">网站方案</a></li><li><a href="https://www.cdcxhl.com/idc/wenjiang.html" title="温江服务器托管" target="_blank">温江服务器托管</a></li><li><a href="http://www.szruijie.cn/" title="瑞捷酒店用品" target="_blank">瑞捷酒店用品</a></li>            </ul>
        </div>
    </div>
    <div class="bot-footer">
        <div class="wp">
            <p class="wpss"> <em>Copyright © 2002-2023 www.csdahua.cn 快上网建站品牌 QQ:244261566 版权所有</em> <em>备案号:<a href="http://beian.miit.gov.cn/" rel="external nofollow">蜀ICP备19037934号</a></em>
            </p>
            <p class="wpss" style="line-height:30px !important;"> </p>
        </div>
    </div>
    <div class="footer-kefu">
        <ul>
            <li class="qq"><a href="https://wpa.qq.com/msgrd?v=3&uin=244261566&site=qq&menu=yes"><em></em>在线咨询</a>
            </li>
            <li class="tel"><a href="tel:13518219792" target="_blank"><em></em>13518219792</a></li>
            <li class="wx"> <em></em>
                <div class="code"> <img src="/Public/Home/images/ew.jpg" />
                    <p>微信二维码</p>
                </div>
            </li>
            <li class="m"> <em></em>
                <div class="code"> <img src="/Public/Home/images/ew.jpg" />
                    <p>移动版官网</p>
                </div>
            </li>
            <li class="top"><em></em></li>
        </ul>
    </div>
    <script src="/Public/Home/js/all.js"></script>
</body>
</html>
<script>
    $(".cont 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>