日期:2014-05-19  浏览次数:20515 次

关于在Repeater中批量删除的问题
我在网上找了下方法,基本想到思想,可实际操作碰到一些问题,麻烦高手帮忙看一下.
前台:
<asp:repeater   id= "TestList "   runat= "server ">
<ItemTemplate>
<tr>
<td   height= "24 "   align= "center "> <asp:checkbox   id= "selectid "   runat= "server "> </asp:checkbox> <INPUT   id= "idname "   type= "hidden "   name= "fieldname "   runat= "server "   value= ' <%#   DataBinder.Eval(Container.DataItem, "ID ")   %> '> </td>
<td> .. <td>
...
后台:
private   void   Button1_Click(object   sender,   System.EventArgs   e)
{
string   sID= " ";
foreach   (RepeaterItem   item   in   this.TestList.Items)  
{  
CheckBox   chkbox1   =   (CheckBox)item.FindControl( "selectid ");  

if   (chkbox1.Checked   ==   true)  
{                                          
sID   +=   ((HtmlInputHidden)item.FindControl( "fieldname ")).Value   +   ', ';        
}  
....                              
}  
}

现在的问题是程序运行到foreach后不会执行里面的代码,而直接跳出,但明明这个Repeater是有内容的,请问问题出在哪?


------解决方案--------------------
private void del_Click(object sender, System.EventArgs e)
{
int index;
index=Session[ "module_authority "].ToString().IndexOf( "80 ");
if(index> 0)
{
string ID= " ",Selected_Date= " ";
foreach(RepeaterItem item in this.Repeater.Items)
{
CheckBox ck=(CheckBox)item.FindControl( "checkbox_del ");
if(ck.Checked)
{
HtmlInputHidden inputhidden = (HtmlInputHidden)item.FindControl( "SelectedID ");
ID +=inputhidden.Value.Trim()+ ", ";
HtmlInputHidden inputhidden2 = (HtmlInputHidden)item.FindControl( "Selected_Date ");
Selected_Date +=inputhidden2.Value.Trim()+ ", ";
}
}
if(ID.Length == 0)
this.Page.RegisterStartupScript( " ", " <script> alert( '没有选定删除项 ');window.location.href=window.location.href; </script> ");
else
{
ID = ID.Remove(ID.Length - 1,1);
Selected_Date = Selected_Date.Remove(Selected_Date.Length-1,1);
string sql_del = "delete from Files where ID in( "+ID+ ") ";
string [] Arr_Id = ID.Split( ', ');
for(int i=0;i <Arr_Id.Length;i++)
{
string strsql= "select FileName from Files where id = "+Arr_Id[i];
Con.Open();
SqlCommand cmd =new SqlCommand(strsql,Con);
SqlDataReader dr1 =cmd.ExecuteReader();
if(dr1.HasRows)
while(dr1.Read())
{
string File_Path = Server.MapPath( "../../Files/WeeklyReport/ "+dr1[ "FileName "].ToString().Trim());
if(File.Exists(File_Path))
File.Delete(File_Path);
}
Con.Close();
}

Conn.ExecuteNonQuery_Sql_alert_refurbish_self(this,sql_del, "删除成功!!! "