GridView's UpdateMethod not firing

怎甘沉沦 提交于 2019-12-20 05:38:51

问题


I've got a GridView that I bind to a ObjectDataSource programmatically, like:

ObjectDataSource risks = new ObjectDataSource("Risks", "RetrieveProjectRisk");
risks.TypeName = "Promanto.ProjectRisks";
risks.DataObjectTypeName = "Promanto.ProjectRisk";
risks.SelectMethod = "RetrieveProjectRisk";
risks.DeleteMethod = "DeleteProjectRisk";
risks.InsertMethod = "AddProjectRisk";
risks.UpdateMethod = "UpdateProjectRisk";
risks.SelectParameters.Add("WhereClause", TypeCode.String, "ProjectID  ='PR0002'");
RisksGrid.DataSource = risks;
RisksGrid.DataBind();

But when I click the edit button and I then update my values, I firstly get an error that RowUpdating should exist. When I add it, I'm not sure what to put in it. Isn't my UpdateMethod "UpdateProjectRisk" suppose to fire automatically?


回答1:


When you use ObjectDataSource, providing the UpdateMethod isn't enough.

Your update method will need parameters as to which row to update. The gridview does not provide this on its own.

You need to implement the RowUpdating to provide the UpdateParameters needed to updated your ObjectDataSource

Take a look at this ObjectDataSource Example



来源:https://stackoverflow.com/questions/11756589/gridviews-updatemethod-not-firing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!