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

如何遍历DATALIST中的CheckBox
我在模板列里面加了个CHECKBOX,想实现删除的时候选中的删除,在单击事件里如果遍历Checkboxk呢。

------解决方案--------------------
for(int n=0;n <DataList1.Items.Count;n++)
{
CheckBox cb=(CheckBox)DataList1.Items[n].Cells[0].FindControl( "CheckBox2 ");
if(cb.Checked)
{
int id=int.Parse(DataList1.DataKeys[DataGrid1.Items[n].ItemIndex].ToString());
login1.DeleteOne();
}
}

------解决方案--------------------
for (int i = 0; i < grd.Rows.Count; i++)
{
bool temp = ((CheckBox)grd.Rows[i].FindControl( "CheckBox1 ")).Checked;
if (temp)
{
这里可以进行操作
}
}
------解决方案--------------------
DataList和gridview都有了,我还说啥?
------解决方案--------------------
http://community.csdn.net/Expert/topic/5772/5772305.xml?temp=.7656214

看其中的管理部分代码,就是管理员登陆后,在各个分类列表里有删除\置顶\精华等按钮功能,看Mainlist.aspx.cs代码就可以找到了.