【发布时间】:2011-03-22 11:27:44
【问题描述】:
除了使用索引之外,还有其他方法可以删除 gridview 列吗? 我正在使用带有多个复选框的gridview。 我想删除所有那些复选框被选中的列.. 我正在检索复选框..
protected void ButtonApprove_Click(object sender, EventArgs e)
{
StringCollection sc = new StringCollection();
string id = string.Empty;
for (int i = 0; i < GridView1.Rows.Count; i++)//loop the GridView Rows
{
//find the CheckBox
CheckBox cb =
(CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBox1");
if (cb != null)
{
if (cb.Checked)
{
// get the id of the field to be deleted
id = GridView1.Rows[i].Cells[1].Text;
// add the id to be deleted in the StringCollection
sc.Add(id);
}
}
}
UpdateRecords(sc);
}
【问题讨论】:
-
更多信息请您在做什么以及您到底需要什么
-
所以你想删除所有选中的记录吧
-
正是..我想删除所有选中的并将它们添加到另一个gridview
-
即使您是从博客中编写此代码,为什么您无法执行此操作,请将上一个问题标记为已解决的答案
-
为什么要删除以及为什么要添加到另一个网格视图