在DBGRID中,常需要更新一行中的某一个字段,一个简便的方法如下:
在DBGRID加如下属性:
OnCancelCommand = "dgReviews_Cancel" OnEditCommand = "dgReviews_Edit" OnUpdateCommand = "dgReviews_Update"
然后在服务器端加上对应的方法就OK了
protected void dgReviews_Update(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
TextBox content = (TextBox)e.Item.Cells[3].Controls[1];
TextBox reply = (TextBox)e.Item.Cells[3].Controls[3];
Response.Write();
}
protected void dgReviews_Edit(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
dgReviews.EditItemIndex = e.Item.ItemIndex;
BindList(Request.QueryString["type"].ToString());
}
protected void dgReviews_Cancel(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
dgReviews.EditItemIndex = -1;
BindList(Request.QueryString["type"].ToString());
}