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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 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
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0