ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 使用GridView管理类

使用GridView管理类

原创 Linux操作系统 作者:iDotNetSpace 时间:2010-04-07 14:23:44 0 删除 编辑

生成grid_RowEditing事件

编辑

protected void grid_RowEditing(object sender,GridViewEditEventArgs e)

{

grid.EditIndex = e.NewEditIndex;

grid.DataSource = Catalog.Get();

grid.DataBind();

}

退出编辑

protected void grid_RowCancelingEdit(object sender,GridViewCancelEditEventArgs e)

{

grid.EditIndex = -1;

grid.DataSource = Catalog.Get();

grid.DataBind();

}

 

点击更新按钮,触发事件

protected void grid_RowUpdating(object sender,GridViewUpdateEventArgs e)

{

string id = grid.DataKeys[e.RowIndex].Value.ToString();

string Name =  ((TextBox)grid.Rows[e.RowIndex].Cells[0].Controls[0].Text;

string X =  ((TextBox)grid.Rows[e.RowIndex].Cells[1].Controls[0].Text;

...

bool success = DB.ExecuteNonQuery();

grid.EditIndex = -1;

statusLabel.Text = success ? "更新成功":"更新失败";

grid.DataSource = Catalog.Get();

grid.DataBind();

}

 

点击删除按钮,触发

prodected void grid_RowDeleting(object sender,GridViewDeleteEventArgs e)

{

string id =grid.DataKeys[e.RowIndex].Value.String();

bool success = Catalog.Delete(id);

grid.EditIndex = -1;

grid.DataSource = Catalog.Get();

grid.DataBind();

}

0
0
(请您对文章做出评价)

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/12639172/viewspace-631507/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: ASP.NET异常处理
请登录后发表评论 登录
全部评论

注册时间:2008-01-04

  • 博文量
    2376
  • 访问量
    5766219