DataList CheckBox多选删除时处理方法

时间:2022-04-24 10:39:41

前台  
  <asp:datalist   id="score"   runat="server"   Width="780"   Height="80px">  
  <headertemplate>  
  </headertemplate>  
  <itemtemplate>  
  <table   width="780"   border="0"   cellpadding="0"   cellspacing="0">  
  <tr   id="chk"   height="30"   Runat="server">  
  <td   width="30">  
  <div   align="Center">  
  <input   type="hidden"   id="SelectedID"   runat="server"   value='<%#   DataBinder.Eval(Container.DataItem,   "id")%>'   NAME="SelectedID"/>  
  <asp:CheckBox   ID="chkExport"   onclick="javascript:clickcompareBox(this);"   Runat="server"   />  
  </div>  
  </td>  
  <td   width="390"   rowspan="1"   class="zhong13h"><a   href='trydetail.aspx?id=<%#   DataBinder.Eval(Container.DataItem,"id").ToString()   %>'   target=_blank>  
  <%#   CutString(DataBinder.Eval(Container.DataItem,"title").ToString(),27)   %>  
  </a>  
  </td>  
  <td   width="260"   class="zhong13h">  
  <%#   CutString(DataBinder.Eval(Container.DataItem,"keys").ToString(),17)   %>  
  </td>  
  <td   width="100"   rowspan="1"   class="zhong13h"><div   align="center"><%#   DataBinder.Eval(Container.DataItem,"lutime","{0:D}").ToString()   %></div>  
  </td>  
  </tr>  
  </table>  
  </itemtemplate>  
  <alternatingitemtemplate>  
  <table   width="780"   border="0"   cellpadding="0"   cellspacing="0">  
  <tr   id="chk"   height="30"   bgcolor="#f6f6f6"   Runat="server">  
  <td   width="30">  
  <div   align="Center">  
  <input   type="hidden"   id="SelectedID"   runat="server"   value='<%#   DataBinder.Eval(Container.DataItem,   "id")%>'   NAME="SelectedID"/>  
  <asp:CheckBox   ID="chkExport"   onclick="javascript:clickcompareBox(this);"   Runat="server"   />  
  </div>  
  </td>  
  <td   width="390"   rowspan="1"   class="zhong13h"><a   href='trydetail.aspx?id=<%#   DataBinder.Eval(Container.DataItem,"id").ToString()   %>'   target=_blank>  
  <%#   CutString(DataBinder.Eval(Container.DataItem,"title").ToString(),27)   %>  
  </a>  
  </td>  
  <td   width="260"   class="zhong13h">  
  <%#   CutString(DataBinder.Eval(Container.DataItem,"keys").ToString(),17)   %>  
  </td>  
  <td   width="100"   rowspan="1"   class="zhong13h"><div   align="center"><%#   DataBinder.Eval(Container.DataItem,"lutime","{0:D}").ToString()   %></div>  
  </td>  
  </tr>  
  </table>  
  </alternatingitemtemplate>  
  </asp:datalist>  
   
   
  <SCRIPT   language="javascript">  
        bgColor   =   "FEEEE0";  
   
       
      function   clickcompareBox(box)   {  
   
  if(box.checked){  
   
      if(box.id.length==21)  
      {  
        var   trTag   =document.getElementById(box.id.substring(0,15));  
      //   var   trTag=score__ctl1_chk;  
        trTag.bgColor=bgColor;  
    //     score__ctl1_chk.bgColor=bgColor;  
    //     alert(trTag);  
    //alert(trTag.length);  
      }  
      else  
      if(box.id.length==22)  
      {  
        var   trTag   =document.getElementById(box.id.substring(0,16));  
        trTag.bgColor=bgColor;  
      }  
      else  
      if(box.id.length==23)  
      {  
      var   trTag   =document.getElementById(box.id.substring(0,17));  
        trTag.bgColor=bgColor;  
      }  
       
  }    
  else    
  {  
      if(box.id.length==21)  
      {  
        var   trTag   =document.getElementById(box.id.substring(0,15));  
        var   countId   =   box.id.substring(10,11);  
      }  
      else  
      if(box.id.length==22)  
      {  
        var   trTag   =document.getElementById(box.id.substring(0,16));  
        var   countId   =   box.id.substring(10,12);  
      }  
      else  
      if(box.id.length==23)  
      {  
      var   trTag   =document.getElementById(box.id.substring(0,17));  
      var   countId   =   box.id.substring(10,13);  
      }  
      if(countId%2   !=   0){  
  trTag.bgColor="ffffff";  
      }else{  
  trTag.bgColor="F6F6F6";  
      }  
  }  
      }  
       
     
  </SCRIPT>  
   
  后台:-----------------------  
   
  //    
   
  System.Web.UI.WebControls.CheckBox   chkExport;  
  System.Collections.ArrayList   oExArgs   =   new   System.Collections.ArrayList();  
  string   sID;  
  string   id;  
  foreach(DataListItem   oDataListItem   in   score.Items)  
  {  
  chkExport   =   (CheckBox)oDataListItem.FindControl("chkExport");  
  if(   chkExport.Checked)  
  {  
  sID   =   ((HtmlInputHidden)oDataListItem.FindControl("SelectedID")).Value;  
  oExArgs.Add(sID);  
  }  
  }  
  int   i   =   0;  
  string   s="select   id,title,keys,content,cw_pic,d_class,x_class,lutime   from   cw_jy   where   1=1   ";  
  string   s1="";  
  for(   i   =   0;i<oExArgs.Count;i++)  
  {  
  if   (oExArgs[i]!=null)  
  {  
  id=oExArgs[i].ToString().Trim();  
  if   (i==0)  
  {  
  s1=s1+"   and   id="+id;//这里是我自己写的,请在这里构造你的删除语句ok(就是改成你自己的动作即可)  
  }  
  else  
  {  
  s1=s1+"   or   id="+id;  
  }                      
   
  }  
  else  
  {  
   
  Response.Write("<script   laguage='javascript'>history.back();</script>");  
  }  
   
   
   
  }  
  if(s!=(s+s1))  
  {  
  Session["str"]=s+s1;  
   
   
  Response.Write("<script   laguage='javascript'>window.open('detail.aspx');</script>");  
  }  
  else  
  {  
          Response.Write("<script   laguage='javascript'>alert('请选择!');</script>");  
  }