我们专注孝感网站设计 孝感网站制作 孝感网站建设
成都网站建设公司服务热线:18982081108

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

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://www.ytofo.com/article/jhiish.html">http://www.ytofo.com/article/jhiish.html</a>
        </div>
    </div>
    <div class="other">
        <h3>其他资讯</h3>
        <ul>
            <li>
                    <a href="/article/dosdsii.html">python中的阶跃函数 用python计算阶跃函数</a>
                </li><li>
                    <a href="/article/dosdsie.html">linux中命令 linux中命令替换是什么</a>
                </li><li>
                    <a href="/article/dosdsee.html">mysql怎么写一个序列 mysql怎么查询创建的序列</a>
                </li><li>
                    <a href="/article/dosdssp.html">php取数组所有数据 php取出多维数组的值</a>
                </li><li>
                    <a href="/article/dosdsgs.html">php分析三十天内数据 php 数据分析</a>
                </li>        </ul>
    </div>
</div>
<footer>
    <div class="message">
        <div class="mess container">
            <p>免费获取网站设计制作与品牌网站建设策划方案报价</p>
            <span>网站设计 + 品牌建站,策划方案 + 精准报价,现在免费领!品牌要升级,官网先发力!免费领取网站设计制作方案 + 精准报价,专业团队帮你落地</span>
            <form action="">
                <input type="text" class="ipt1" placeholder="联系人">
                <input type="text" class="ipt2" placeholder="联系电话">
                <textarea name="" id=""  placeholder="内容描述:描述您的需求,如网站、微信、电商、APP等。"></textarea>
                <a href="">提交需求</a>
            </form>
        </div>
    </div>
    <div class="footA">
        <div class="footAs container">
            <ul>
                <h3>联系我们</h3>
                <b>18980820575</b>
                <li>手机:13518219792</li>
                <li>地址:湖北孝感市大悟城关镇鄂北物流城13栋125号</li>
                <li class="hr1"></li>
                <li>24小时服务热线:18982081108</li>
            </ul>
            <ul>
                <h3>网站建设服务</h3>
                <li>网页设计</li>
                <li>网站制作</li>
                <li>网站开发</li>
            </ul>
            <ul>
                <h3>网站推广服务</h3>
                <li>营销网站建设</li>
                <li>百度快速排名</li>
                <li>整站网站推广</li>
            </ul>
            <ul>
                <h3>网站运维服务</h3>
                <li>基础维护</li>
                <li>网站改版</li>
                <li>网站维护</li>
            </ul>
            <ul>
                <h3>FOLLOW US</h3>
                <li class="hr2"></li>
                <li>
                    <dd class="fl"><img src="/Public/Home/img/ewm.png" alt=""><p>微信二维码</p></dd>
                    <dd class="fr"><img src="/Public/Home/img/ewm.png" alt=""><p>微信二维码</p></dd>
                </li>
            </ul>
        </div>
        <div class="link container">
            友情链接:
            <a href="http://www.cdkjz.cn/" title="高端网站设计" target="_blank">高端网站设计</a>   <a href="http://www.pjfdj.com/" title="蒲江帕金斯发电机" target="_blank">蒲江帕金斯发电机</a>   <a href="http://www.cxhljz.cn/wechat/" title="微信公众号开发" target="_blank">微信公众号开发</a>   <a href="https://www.cdcxhl.com/tuoguan/" title="服务器托管" target="_blank">服务器托管</a>   <a href="https://www.cdxwcx.com/wangzhan/dingzhi.html" title="成都网站定制" target="_blank">成都网站定制</a>   <a href="http://www.cdfdjby.com/" title="成都发电机保养" target="_blank">成都发电机保养</a>   <a href="http://www.cdganxi.cn/" title="cdganxi.cn" target="_blank">cdganxi.cn</a>   <a href="https://www.cdxwcx.com/jifang/guanghua.html" title="成都光华机房" target="_blank">成都光华机房</a>   <a href="http://www.cdxwcx.cn/tuoguan/meishan.html" title="眉山电信机房" target="_blank">眉山电信机房</a>   <a href="http://www.pvvpwt.com/" title="成都维修发电机" target="_blank">成都维修发电机</a>           </div>
    </div>
    <div class="footB">
        <div class="container">
            <div class="fl">
                Copyright © 2025  湖北孝感网站建设公司     湖北孝感网站建设公司-选我们!湖北专业的孝感网站制作公司!
            </div>
            <div class="fr">
                All Rights Reserved 版权所有 <a href="https://beian.miit.gov.cn/" target="_blank" rel="nofollow">鄂ICP备2025125038号-8</a>
            </div>
        </div>
    </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>