使用GridView管理類

iDotNetSpace發表於2010-04-07

生成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部落格 ” ,連結:http://blog.itpub.net/12639172/viewspace-631507/,如需轉載,請註明出處,否則將追究法律責任。

相關文章