• GridView中实现单选RadioButton


    注意:若在gridview内对radiobutton用组名groupname同名方法行不同,若加上GroupName="skytest"查看静态页面源代码便知道:两个name值的组名都不同。

    下面结合js实现单选.

    呈现页:

    <asp:GridView ID="GridView1" Width="960px" EmptyDataText="暂无标书可操作"
                DataKeyNames="ID" AutoGenerateColumns="false" runat="server" onrowdatabound="GridView1_RowDataBound"
                >
                <Columns>
                    <asp:TemplateField HeaderText="选择">
                        <ItemTemplate>
                        <asp:RadioButton ID="RadioButton1" runat="server"    />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="ID" HeaderText="标书编号" />

              </Columns>
      </asp:GridView>

    代码页:

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    RadioButton rb = (RadioButton)e.Row.FindControl("RadioButton1");
                    if (rb != null)
                    {
                      rb.Attributes.Add("onclick", "single(this)");  //single(obj)为js函数 
                    }
                }

            }

    需要添加的javascript函数:

    <script type="text/javascript">
        var last=null;
        function single(obj)
        {
          if(last==null)    //第一次选择RadioButton时赋id值给last
          {
             last=obj.id; 
          }
          else            //第一次以后的每一次都在这运行,把上此的RadioButton.Checked=false,记下此次的obj.name
          {
            var lo=document.getElementById(last);
            lo.checked=false;
            last=obj.id;
          }
          obj.checked="checked";   //添加checked属性,以便在上边赋值为false
        }
        </script>

  • 相关阅读:
    SQL 2008R2问题:用户、组或角色'XXX'在当前数据库中已存在?
    修改sqlserver 2008 R2 实例名称
    keepalived vip做网关
    Django(HttpResponse、render,、redirect)的用法
    Linux脚本中$#、$0、$1、$@、$*、$$、$?
    linux定时删除历史日志文件实现方式--shell脚本
    Long转换为date
    java.lang.ClassNotFoundException: org.springframework.web.util.IntrospectorCleanupListener
    2016年新年伊始
    linux下环境搭建
  • 原文地址:https://www.cnblogs.com/liufei88866/p/1891986.html
Copyright © 2020-2023  润新知