日期:2014-05-19  浏览次数:20547 次

关于DataGrid删除一行问题
下面这个代码是我封装在类里面的
public   bool   DelData(string   TableName,string   eId)
{
    dp.CommandText   =   "DELETE   FROM   [ "+TableName+ "]   WHERE   Id   =   @Id ";
    dp.Parameter.Add( "Id ",eId);
if(dp.ExecuteNonQuery()!=0)
{
return   true;
}
else
{
    return   false;
}
}
下面这个代码是我的删除事件代码
private   void   dg_DeleteCommand(object   source,   System.Web.UI.WebControls.DataGridCommandEventArgs   e)
{
         
// dp.CommandText   =   "DELETE   FROM   [User_editor]   WHERE   Id     =   "+e.Item.Cells[0].Text.Trim()+ " ";
// DataTable   dt   =   dp.DataTableSQL( "User_editor ");
// bind.BindInfo_DataGrid(dg,dt, " ");
if(this.DelData( "User_editor ",e.Item.Cells[5].Text.Trim()))
{
Response.Write( " <script   language=javascript> alert( '删除操作成功! ');location.href= 'CheckEditor.aspx '; </script> ");
}
else
{
Response.Write( " <script   language=javascript> alert( '系统错误,删除操作失败! '); </script> ");
}


}
请问大侠我在删除的时候为什么事件没有反应呢

------解决方案--------------------
在datagrid的里面建立一个button列,然后写下代码,就可以实现删除了,
if(dgShow.Items.Count==1)
{
if(dgShow.CurrentPageIndex!=0)
dgShow.CurrentPageIndex = dgShow.CurrentPageIndex-1;
}
string strSql = "delete from tbStudentinfo where studentid= "+e.Item.Cells[0].Text+ " ";
ExecuteSql(strSql);
BindData();