(注: 问题已解决,PageLoad事件中数据加载时一定要写在 !isPostBack 判定内,是否回传页面,如果页面回传,数据重新加载,无法正确获取checkbox的选中状态 Time:2010-02-24 12:08)
在网上看到很多实例,但是奇怪我怎么写都不能删除选定的记录,这个问题一直烦了我很多天,进度一下子慢了下来。
try
{
string strSql = "";
DataControls.myOpen();
for (int i = 0; i < NewsList.Rows.Count; i++)
{
bool boolChecked = ((CheckBox)NewsList.Rows[i].FindControl("CheckBox1")).Checked;
string strID = ((Label)NewsList.Rows[i].FindControl("Label1")).Text;
if (boolChecked)
{
strSql = "DELETE FROM [News] WHERE ID =" + int.Parse(strID);
OleDbCommand myComm = new OleDbCommand(strSql, DataControls.myConn);
myComm.ExecuteNonQuery();
}
}
NewsList.DataBind();
Response.Redirect("News_Manage.aspx?bigclass=所有新闻", false);
}
catch (Exception ee)
{ throw new Exception(ee.Message); }
finally
{ DataControls.myClose(); }
这是我最新修改的代码,不论我怎么改,就是删除不掉选定的记录,请高人指点一下...