多个gridview(工作代码)的c#代码。这将创建多个网格视图,但删除和编辑不起作用。
GridView gv = new GridView();
// gv.DeleteMethod("DeleteData");
gv.ID = "_gridview" + categoryId;
gv.AutoGenerateEditButton = true;
gv.AutoGenerateDeleteButton = true;
gv.DataSource = objSpearController.GetSpearSiteDetails(siteID, categoryId);
gv.DataBind();
GridPlaceHolder.Controls.Add(gv);
GridPlaceHolder.Controls.Add(new LiteralControl("<br />"));
gv.BackColor = System.Drawing.Color.FromName(resourceSet.GetString(categoryId.ToString()));
gv.RowDeleting += new GridViewDeleteEventHandler(gv_RowDeleting);
上述代码的事件处理程序。抱歉错误。我是初学者。
public void gv_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
GridView gv = (GridView)sender;
try
{
int SiteId = int.Parse(ddlSiteName.SelectedValue);
int result = objSpearController.deleteSbdData(SiteId);
LoadSpearSiteNames();
ddlCategory.SelectedIndex = 0;
}
catch (Exception ex)
{
lblError.Text = ex + "error";
}
}