飞凡团队

使用GridView管理类

生成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();

}

posted on 2010-04-07 10:24  飞凡团队  阅读(985)  评论(1)    收藏  举报