JQuery实现全选 与 批量删除

<script language="javascript" type="text/javascript" src="http://www.cnblogs.com/js/JQuery/jquery-1.4.1-vsdoc.js"></script>

<script type="text/javascript" defer="defer">

//全选的脚本
   $(function()
   {
        $("#chkAll").click(function()
        {
            if($(this).attr("checked")==true)
            {

      //对于checkBox是.net服务器控件时可以这样做,$(":checkbox").each(function(){});      
                $("input[name='chkBulletin']").each(function()
                {
                    $(this).attr("checked",true);
                });
            }
            else
            {

      //对于checkBox是.net服务器控件时可以这样做,$(":checkbox").each(function(){}); 
                $("input[name='chkBulletin']").each(function()
                {
                    $(this).attr("checked",false);
                });
            }
        });
   });  
  
  //批量删除保存所选项的ID的脚本     
   function Delete()
   {
        if(confirm("确定删除吗?")==true)
        {
           
                var text="";

      //对于checkBox是.net服务器控件时可以这样做,$(":checkbox").each(function(){}); 
                $("input[name='chkBulletin']").each(function()
                {                   
                    if($(this).attr("checked")==true)
                    {
                        text += $(this).val() +";";
                    }
                  
                });
                if(text=="")
                {
                    alert("请选择要删除的数据!");
                    return false;
                }
                else
                {
                   var tempText = text.substring(0, text.length - 1);
                   $('#<%=hfBulletinID.ClientID %>').val(tempText);
                }
                alert($('#<%=hfBulletinID.ClientID %>').val());
                return true;
         
        }
        else
        {
           return false;
        }
    }
 </script>

 

<table>

  <tr>

    <td valign="top" class="headerButtonsTopPadding">
                        <asp:ImageButton ID="ibtnBatchDelete" runat="server"  ImageUrl="~/images/icon/icon-delete.gif"
                            OnClientClick='Delete();'  οnclick="ibtnBatchDelete_Click" />批量删除                                              
           </td>

  </tr>

  

  <tr>
       <td  valign="top">
        <asp:GridView ID="gvBulletin" runat="server" Width="100%" AutoGenerateColumns="False" DataKeyNames="ID" CssClass="Grid"  >
            <Columns>
                <asp:TemplateField>
                    <HeaderTemplate><input type="checkbox" id="chkAll" name="chkAll" value="全选"  /></HeaderTemplate>
                    <ItemTemplate >
                        <input type="checkbox" id="chkBulletin" value='<%#Eval("ID") %>' name="chkBulletin" />
                    </ItemTemplate>                       
                </asp:TemplateField>
                <asp:BoundField DataField="ID" HeaderText="公告ID" Visible="False">
                    <HeaderStyle Wrap="False" />
                </asp:BoundField>
                <asp:HyperLinkField DataNavigateUrlFields="ID"
                    DataNavigateUrlFormatString="~/Pages/Bulletin/BulletinDetail.aspx?id={0}"
                    DataTextField="Title" HeaderText="标题" />               
                <asp:TemplateField HeaderText="摘要">                  
                    <ItemTemplate>
                        <asp:Label ID="lblContent" runat="server" Text='<%# SetContents(Eval("Contents"))%>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Type" HeaderText="类型" ></asp:BoundField>
                <asp:TemplateField HeaderText="阅读人员">                   
                    <ItemTemplate>
                        <asp:Label ID="lblReader" runat="server" Text='<%# SetReader(Eval("ReaderList")) %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="CreatedDate" HeaderText="发布日期" HtmlEncode=false
                    DataFormatString="{0:yyyy-MM-dd}"></asp:BoundField>
                   <asp:TemplateField HeaderText="状态">                      
                       <ItemTemplate>
                           <asp:Label ID="lblStatus" runat="server" Text='<%# Eval("Status").ToString()!=""?Eval("Status").ToString()=="True"?"已发布":"未发布":"" %>'></asp:Label>
                       </ItemTemplate>
                </asp:TemplateField>
                   <asp:TemplateField HeaderText="操作">
                        <ItemTemplate>
                            <div>
                                <nobr>
                                    <img alt="修改公告" src="http://images.cnblogs.com/ToolBar/toolbaredit.gif"

       οnclick="UniversalOpenWindowAndBreak(600,500,'BulletinEdit.aspx?bulletinId=<%#Eval("ID") %>',1)"/ >                                  
                                   &nbsp;&nbsp;&nbsp;&nbsp;
                                   <asp:LinkButton ID="lkBtnDelete" runat="server"
                                    OnClientClick='javascritp:return confirm("确定要删除这条公告吗?");'
                                    οnclick="lkBtnDelete_Click" >删除</asp:LinkButton>                                                                    
                                </nobr>
                            </div>
                        </ItemTemplate>
                   </asp:TemplateField>
                </Columns>

            </asp:GridView>
         </td>          
      </tr>   

</table>

 

//如下是后台得到所选项的ID代码:

string bulletinId = hfBulletinID.Value;

string[] bulletinArr = bulletinId.Split(new char[] { ';' });//转换为数据

转载于:https://www.cnblogs.com/vihone/archive/2010/07/01/1768783.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值