zoukankan      html  css  js  c++  java
  • [转]Gridview中实现RadioButton单选效果

    HTML

    <asp:TemplateField ItemStyle-Width="22px">
                               <ItemTemplate>
                                   <asp:RadioButton ID="radButtonControl" GroupName="group1" runat="server" />
                               </ItemTemplate>
                           </asp:TemplateField>

    CS

    protected void gvWorkPlanList_RowDataBound(object sender, GridViewRowEventArgs e)
           {
               if (e.Row.RowType == DataControlRowType.DataRow)
               {
                   RadioButton rb = (RadioButton)e.Row.FindControl("radButtonControl");
                   if (rb != null)
                       rb.Attributes.Add("onclick", "onRadiobuttonClick('" + this.gvWorkPlanList.ClientID + "','" + rb.ClientID + "')");  
               }
           }

    JS

    /**//*
    传入的GridviewClientID和所选的RadioButton ClientID
    **/
      function onRadiobuttonClick(gvControlID,selectedControlId)
      {
           var inputs = document.getElementById(gvControlID).getElementsByTagName("input");
           for(var i=0; i <inputs.length; i++)
           {
               if(inputs[i].type=="radio")
               {
                   if(inputs[i].id==selectedControlId)
                       inputs[i].checked = true;
                   else
                       inputs[i].checked = false;
                  
               }
           }
      }
  • 相关阅读:
    Https的请求过程
    计算机网络知识
    数据结构之图
    Python3线程池进程池
    数据结构之堆heapq
    EffectivePython并发及并行
    EffectivePython类与继承
    EffectivePython并发及并行
    5.19完全数
    5.18数字全排列
  • 原文地址:https://www.cnblogs.com/bluewhale84/p/4074151.html
Copyright © 2011-2022 走看看