百思不得其解,Repeater批量删除时FindControl不到控件
ASPX页代码:
<asp:Repeater ID= "Repeater1 " runat= "server ">
<HeaderTemplate>
<table width= "100% " border= "0 " cellpadding= "1 " cellspacing= "1 " bgcolor= "#C4CACD ">
<tr>
<td height= "22 " bgcolor= "#F2F4F6 "> <input class= "selFlag " name= "checkbox " type= "checkbox " title= "全选 " onclick= "CheckAll( 'form1 ',this.checked) " value= "checkbox " /> </td>
<td height= "22 " align= "center " bgcolor= "#F2F4F6 "> Username </td>
<td align= "center " bgcolor= "#F2F4F6 "> ParentID </td>
<td align= "center " bgcolor= "#F2F4F6 "> Code </td>
<td align= "center " bgcolor= "#F2F4F6 "> GroupID </td>
<td align= "center " bgcolor= "#F2F4F6 "> GroupCode </td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td bgcolor= "#FFFFFF "> <input type= "checkbox " class= "selFlag " id= "selID " value= " <%#DataBinder.Eval(Container.DataItem, "id ")%> " runat= "server " enableviewstate= "true " /> </td>
<td height= "20 " bgcolor= "#FFFFFF "> <%#DataBinder.Eval(Container.DataItem, "Username ")%> </td>
<td bgcolor= "#FFFFFF "> <%#DataBinder.Eval(Container.DataItem, "ParentID ")%> </td>
<td bgcolor= "#FFFFFF "> <%#DataBinder.Eval(Container.DataItem, "Code ")%> </td>
<td bgcolor= "#FFFFFF "> <%#DataBinder.Eval(Container.DataItem, "GroupID ")%> </td>
<td bgcolor= "#FFFFFF "> <%#DataBinder.Eval(Container.DataItem, "GroupCode ")%> </td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<asp:Button ID= "btnDel " runat= "server " Text= "删除 " OnClick= "btnDel_Click " />
CS代码:
protected void btnDel_Click(object sender, EventArgs e)
{
//for (int i = 0; i < this.Repeater1.Items.Count; i++)
foreach (RepeaterItem myItems in this.Repeater1.Items)
{
//HtmlInputCheckBox myCheckBox = (HtmlInputCheckBox)this.Repeater1.Items[i].FindControl( "selID ");
HtmlInputCheckBox myCheckBox = (HtmlInputCheckBox)myItems.FindControl( "selID ");
if (myCheckBox != null)
{
lblMsg.Text = myCheckBox.Value;
return;
if (myCheckBox.Checked)
{
string tmpID = myCheckBox.Value.Trim();
myData.ExecuteNonQuery( "delete from [User] where id= " + tmpID + " ");
}
}
}
//Response.Redirect( "list.aspx ");
}
[解决办法]
string IDs = " ";
for (int i = 0; i < Repeater1.Items.Count; i++)
{
if (((HtmlInputCheckBox)this.Repeater1.Items[i].FindControl ( "selID ")).Checked == true)
{
if (IDs == " ")
{
IDs = ((HtmlInputCheckBox)this.Repeater1.Items[i].FindControl( "selID ")).Value;
}
else
{
IDs += ", " + ((HtmlInputCheckBox)this.Repeater1.Items[i].FindControl( "selID ")).Value;
}
}
}
[解决办法]
Text= " <%#DataBinder.Eval(Container.DataItem, "id ")%> "
怎么可能都是双引号
try this
Text= ' <%#DataBinder.Eval(Container.DataItem, "id ")%> '