我刚刚读了这个问题,但如果你还没有弄清楚,那么你可以做什么去你的 aspx 文件并在 gridview 下定义“OnRowEditing”。然后回到文件后面的代码并执行以下操作:
protected void gvEvents_Edit(object sender, GridViewEditEventArgs e)
{
//Set the edit index.
gvEvents.EditIndex = e.NewEditIndex;
DataTable dt = Session["dtEvents"] as DataTable;
//Bind data to the GridView control.
gvEvents.DataSource = Session["dtEvents"];
gvEvents.DataBind();
}
您还需要定义 OnRowUpdating 和 OnRowCancelingEdit 并将它们的代码放在后面的代码中。这是 OnRowCancelingEdit 下的内容
protected void gvEvents_cancEdit(object sender, GridViewCancelEditEventArgs e)
{
//Reset the edit index.
gvEvents.EditIndex = -1;
//Bind data to the GridView control.
DataTable dt = Session["dtEvents"] as DataTable;
gvEvents.DataSource = Session["dtEvents"];
gvEvents.DataBind();
}