zoukankan      html  css  js  c++  java
  • 在GridView中用Js实现全选

      有的时候,在GridView要用的CheckBox,并且,还有一个实现全选的CheckBox,所以我在下面把js代码贴在下面,
    <script language=javascript>
    function Sel()
    {
    oEl 
    = event.srcElement;

    for(i = 0;i < document.all.length; i++)
    {
                                                  
    // datagrid将生成层次名+id作为客户端id
    if(document.all(i).id.indexOf("你的CheckBox的ID"!= -1)
    {
    if(oEl.checked)
    document.all(i).
    checked = true;
    else
    document.all(i).
    checked = false;
    }
    }
    }
    </script>
    下面是GirdView代码
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound">
                                            
    <Columns>
                                                
    <asp:BoundField DataField="pid" HeaderText="Id" />
    <!--关键是这段代码-->

                                                
    <asp:TemplateField>
                                                
    <HeaderTemplate>
                                                 
    <input id="chkAll" onclick="Sel()"  type="checkbox" />

                                                
    </HeaderTemplate>
                                                    
    <ItemTemplate>
                                                        
    <asp:CheckBox ID="cbselect" runat="server" />
                                                    
    </ItemTemplate>
                                                
    </asp:TemplateField>
    <!--关键是这段代码-->
                                                
    <asp:TemplateField HeaderText="商品名称">
                                                    
    <ItemTemplate>
                                                    
    <a href='DetailProduceInfo.aspx?pid=<%#Eval("pid") %>' target="_blank"><%#Eval("pname"%></a>    
                                                    
    </ItemTemplate>
                                                
    </asp:TemplateField>
                                                
    <asp:TemplateField HeaderText="单价">
                                                    
    <ItemTemplate>
                                                          
    <%#Eval("pmoney"%>
                                                    
    </ItemTemplate>
                                                
    </asp:TemplateField>
                                                
    <asp:TemplateField HeaderText="数量">
                                                    
    <ItemTemplate>
                                                        
    <asp:TextBox ID="txtquantity" runat="server" Width="80px">0</asp:TextBox>
                                                        
    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtquantity"
                                                            ErrorMessage
    ="请你输入数字!" ValidationExpression="^[0-9]{1,}$"></asp:RegularExpressionValidator>
                                                    
    </ItemTemplate>
                                                
    </asp:TemplateField>
                                            
    </Columns>
                                        
    </asp:GridView>
     
  • 相关阅读:
    Consul运行
    springcloud+Zookeeper测试
    解决:sql2005 安装完后 没有服务的问题
    asp.net dataTable添加列
    C#关闭word进程
    无法将类型为“Microsoft.Office.Interop.Word.ApplicationClass”的 COM 对象强制转换为接口类型“Microsoft.Office.Interop.Word._Application”
    C#网页采集
    C#计算时间差值
    C#播放声音
    C#打开得到路径
  • 原文地址:https://www.cnblogs.com/xbf321/p/896068.html
Copyright © 2011-2022 走看看