在datagrid中添加了buttoncolumn列,我想用它来实现"删除"功能,在脚本中我可以删除,但是不用脚本怎么来实现呢??
下面代码,>
String deleteCmd = "delete from commentInfo where commentID = @commentID";
String strConn = ConfigurationSettings.AppSettings["webblog"] + Server.MapPath("WebBlog.mdb");
OleDbConnection cn = new OleDbConnection();
cn.ConnectionString = strConn;
OleDbCommand myCommand = new OleDbCommand(deleteCmd, cn);
myCommand.Parameters.Add(new OleDbParameter("@commentID", OleDbType.VarChar, 38));
myCommand.Parameters["@commentID"].Value =commentDataGrid.DataKeys[e.Item.ItemIndex].ToString();
cn.Open();
myCommand.Parameters.Clear();
myCommand.CommandText = "update contextInfo set viewCount = viewCount - 1 where contextID = '{"+Request["contextID"]+"}'";
myCommand.ExecuteNonQuery();
try
{
myCommand.ExecuteNonQuery();
Message.Text = "删除成功";
}
catch(System.Data.OleDb.OleDbException)
{
Message.Text ="出错了";
}
cn.Close();
但它有个委托事件:
在initialcomponent()里面
this.commentDataGrid.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.commentDataGrid_DeleteCommand);可是我在VS2005中没有发现这个函数,(我认为它是自带的)
但是我重新写了一个这样的函数,可还是不能实现"删除"功能?望高手指点一下!