日期:2014-05-18  浏览次数:20386 次

怎样循环删除呐????
在Repeater中选中多个checkbox,然后点击删除按钮.如何循环删除?以下是部分代码..
for   (int   i   =   0;   i   <   Repeater.Items.Count;   i++)
                {
                        CheckBox   cb   =   (CheckBox)engineer_Repeater.Items[i].FindControl( "checkbox1 ");
                        if   (cb.Checked)
                        {
                                Label   lb   =   (Label)engineer_Repeater.Items[i].FindControl( "label1 ");
}
}

------解决方案--------------------
少了cell
------解决方案--------------------
哦看错了


楼主要删除什么??
------解决方案--------------------
把要删除的主键取出来中间用逗号分开
delete table where id in(主键)
------解决方案--------------------

把要删除的主键取出来中间用逗号分开
delete table where id in(主键)

===============================

说的不错,你现在只要把需要删除的那些 ID取出来 组成 'aa ', 'bb ', 'cc '的字符串 然后就可以执行了
------解决方案--------------------
获取未选中项ID放到ArryList列表中 在后台使用 delete table where id in(主键) sql语句删除即可

------解决方案--------------------
同意igelf,定义变量将id用 ", "号拼起来
再执行sql语句delete from table where id in(变量)
------解决方案--------------------
你删除数据库中的数据,然后重新绑定。
------解决方案--------------------
需要删除的那些 ID取出来 组成 'aa ', 'bb ', 'cc '的字符串 然后就可以执行了
------解决方案--------------------
private void btnDelete_Click(object sender, System.EventArgs e)
{
bool flag = false;
for(int i = 0;i <Grid.Items.Count;i++)
{
CheckBox check = (CheckBox)Grid.Items[i].FindControl( "cb ");
if (check.Checked)
{
string id = Grid.Items[i].Cells[0].Text;
User.Id = int.Parse(id.ToString());
User.AdminDelUser();
flag = true;
}
}

chkSelect.Checked = false;
if (flag)
{
Response.Write( " <script> alert( '删除成功 ');window.location.href= ' "+this.Request.RawUrl+ " '; </script> ");
if (Grid.CurrentPageIndex> 0)
Grid.CurrentPageIndex--;
BindGrid();
}

else
Response.Write( " <script> alert( '没有选择要删除的数据 '); </script> ");

}
------解决方案--------------------
路过
------解决方案--------------------
学习

------解决方案--------------------
CheckBox chkID = null;
int ID = 0;
foreach(DataGridItem dgItem in this.DataGrid1.Items)
{
chkID = (CheckBox)dgItem.FindControl( "RowSelecter ");
if(chkID.Checked)
{
ID=(int)this.DataGrid1.DataKeys[(int)dgItem.ItemIndex];