C#中怎么利用CheckBox实现单选功能-古蔺大橙子建站
RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
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://scgulin.cn/article/jhiish.html">http://scgulin.cn/article/jhiish.html</a>
                                            </div>
                                            <div class="hot_new">
                                                <div class="page_title clearfix">
                                                    <h3>其他资讯</h3>
                                                </div>
                                                <div class="news_list clearfix">
                                                    <ul>
                                                        <li>
                                                                <a href="/article/peochp.html">c语言中形参的默认存储类型以及作用</a>
                                                            </li><li>
                                                                <a href="/article/peochh.html">怎么在js数组的指定位置添加元素</a>
                                                            </li><li>
                                                                <a href="/article/peosdc.html">Linux中如何启动Tomcat</a>
                                                            </li><li>
                                                                <a href="/article/peocso.html">ios中greater<T>()和less<T>()有什么区别</a>
                                                            </li><li>
                                                                <a href="/article/peosos.html">Linux命令:MySQL系列之八--MySQL事务相关内容</a>
                                                            </li>                                                    </ul>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 底部信息 -->
<div class="footer wow fadeInUp">
    <div class="rowFluid">
        <div class="span12">
            <div class="container">
                <div class="footer_content">
                    <div class="span4 col-xm-12">
                        <div class="footer_list">
                            <div class="span6">
                                <div class="bottom_logo"><img src="/Public/Home/images/ewm.jpg" alt="微信服务号二维码" /></div>
                            </div>
                            <div class="span6 col-xm-12">
                                <div class="quick_navigation">
                                    <div class="quick_navigation_title">快速导航</div>
                                    <ul>
                                        <li><a href="https://www.cdxwcx.com/" title="成都做网站" target="_blank">成都做网站</a></li><li><a href="http://www.njzdgg.com/" title="支点广告" target="_blank">支点广告</a></li><li><a href="http://www.scghjhjc.com/" title="广汉锦华建材" target="_blank">广汉锦华建材</a></li><li><a href="https://www.hayoumeiju.com/" title="深圳惠宜防蚊纱窗" target="_blank">深圳惠宜防蚊纱窗</a></li><li><a href="https://www.cdcxhl.com/tuoguan/zongshu/" title="成都棕树机房" target="_blank">成都棕树机房</a></li><li><a href="https://www.cdxwcx.com/city/suining/" title="遂宁做网站" target="_blank">遂宁做网站</a></li><li><a href="http://www.cdkjz.cn/fangan/secu/" title="安防网站建设方案" target="_blank">安防网站建设方案</a></li>                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="span4 col-xm-6 col-xs-12">
                        <div class="footer_list">
                            <div class="footer_link">
                                <div class="footer_link_title">友情链接</div>
                                <ul id="frientLinks">
                                    <a href="https://www.cdcxhl.com/" title="网站制作" target="_blank">网站制作</a>
                                    <a href="https://www.cdcxhl.com/" title="网站建设" target="_blank">网站建设</a>
                                    <a href="https://www.cdxwcx.com/tuiguang/" title="成都网络推广" target="_blank">网络推广</a>
                                    <a href="http://seo.cdkjz.cn/" title="成都网站推广" target="_blank">网站推广</a>
                                    <a href="https://www.cdcxhl.com/xiaochengx.html" title="成都微信小程序开发" target="_blank">小程序开发</a>
                                    <a href="https://www.cdcxhl.com/menu.html" title="创新互联网站栏目导航" target="_blank">网站导航</a>
                                </ul>
                                <div class="footer_link_title">网站建设</div>
                                <ul id="frientLinks">
                                    <li><a href="/">古蔺大橙子建站</a></li>
                                    <li><a href="https://www.cdcxhl.com/menu.html" title="创新互联网站栏目导航" target="_blank">网站导航</a></li>
                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="span4 col-xm-6 col-xs-12">
                        <div class="footer_list">
                            <div class="footer_cotact">
                                <div class="footer_cotact_title">联系方式</div>
                                <ul>
                                    <li><span class="footer_cotact_type">企业:</span><span class="footer_cotact_content">青羊区大橙子信息咨询工作室</span></li>
                                    <li><span class="footer_cotact_type">地址:</span><span class="footer_cotact_content">成都市青羊区太升南路288号</span></li>
                                    <li><span class="footer_cotact_type">电话:</span><span class="footer_cotact_content"><a href="tel:18980820575" class="call">18980820575</a></span></li>
                                    <li><span class="footer_cotact_type">网址:</span><span class="footer_cotact_content"><a href="/" title="古蔺网站建设">www.scgulin.cn</a></span></li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="copyright">
                <p>公司名称:青羊区大橙子信息咨询工作室   联系电话:18980820575</p>
                <p><a href="http://beian.miit.gov.cn" target="_blank" rel="nofollow">网站备案号:蜀ICP备2022028542号-27</a></p>
                <p>古蔺大橙子建站 古蔺网站建设 古蔺网站设计 古蔺网站制作 <a href="http://www.cdxwcx.cn/" target="_blank">成都做网站</a></p>
            </div>
        </div>
    </div>
</div>
</body>
</html>
<script>
    $(".technical_support_box_z_info_box 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>