我今天做个删除单条记录。。但就删不掉。是不是greeview里面属性没有设置正确? /// <summary>
/// 删除单条数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param> protected void GVlist_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string id = this.GVlist.DataKeys[e.RowIndex].Value.ToString();
if(bbdel.GetDelete(int.Parse(id))>0)
{
this.lblshow.Text = "<script>alert('删除成功!')</script>";
BindGreeView();
}
}
/// <summary>
/// 删除一条数据
/// </summary>
public int GetDelete(int Id)
{
string sql = "delete from Books where Id="+Id; return DbHelperSQL.ExecuteSql(sql);
}
/// 删除单条数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param> protected void GVlist_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string id = this.GVlist.DataKeys[e.RowIndex].Value.ToString();
if(bbdel.GetDelete(int.Parse(id))>0)
{
this.lblshow.Text = "<script>alert('删除成功!')</script>";
BindGreeView();
}
}
/// <summary>
/// 删除一条数据
/// </summary>
public int GetDelete(int Id)
{
string sql = "delete from Books where Id="+Id; return DbHelperSQL.ExecuteSql(sql);
}
应该是:
string id = this.GVlist.DataKeys[e.RowIndex]["DataKeyNames的值"].Value.ToString();
如果后台能得到值的话那么你看下
前台删除按钮Command="delete"是否加了这个属性