ObjectDataSource configuration
When you have a gridview bound to an ObjectDataSource, you have to be sure to pass the fields defined in the gridview’s DataKeyNames section to your Delete and Update methods.
Otherwise, you will get an error similar to:
ObjectDataSource 'objDSStatus' could not find a non-generic method 'DeleteContactStatus' that has parameters: ContactStatusId, ContactStatusTypeId.
In this instance I had DataKeyNames=”ContactStatusId, ContactStatusTypeId”, but the DeleteContactStatus method only contained ContactStatusId – the actual primary key.
Also be sure OldValuesParameterFormatString=”{0}”
You don’t need to configure the DeleteParameters in the ObjectDataSource properties as the defined DataKeyNames are passed automatically.
Here is the update code that worked:
Public Sub DeleteContactStatus(_
ByVal ContactStatusId As Integer, _
ByVal ContactStatusTypeId As Integer)
Dim arrParams(0) As SqlParameter
arrParams(0) = New SqlParameter("@iContactStatusId", ContactStatusId)
strSql = "Delete From ContactStatus " & _
"Where ContactStatusId = @iContactStatusId"
SqlHelper.ExecuteNonQuery(cn, CommandType.Text, strSql, arrParams)
End Sub
- Download this code: DeleteContactStatus.txt
Trackback URI |