I am trying to add a parameter to the deleting event of an ObjectDataSource as in the example below from msdn. I generated an event handler for the ObjectDataSource’s deleting event, and it had the same signature as in the example, however, when I try to clear the paramsFromPage as in the example, I receive an error stating that paramsFromPage is readonly. Is there something I need to change somewhere else?
This example comes from the following msdn page:
Private Sub NorthwindEmployeeDeleting(ByVal source As Object, ByVal e As ObjectDataSourceMethodEventArgs)
' The GridView passes the ID of the employee
' to be deleted. However, the business object, EmployeeLogic,
' requires a NorthwindEmployee parameter, named "ne". Create
' it now and add it to the parameters collection.
Dim paramsFromPage As IDictionary = e.InputParameters
If Not paramsFromPage("EmpID") Is Nothing Then
Dim ne As New NorthwindEmployee(paramsFromPage("EmpID").ToString())
' Remove the old EmpID parameter.
paramsFromPage.Clear()
paramsFromPage.Add("ne", ne)
End If
End Sub ' NorthwindEmployeeDeleting
EDIT:
The following is my code
Protected Sub QueueDataSource_Deleting(ByVal sender As Object, ByVal e As ObjectDataSourceMethodEventArgs) Handles QueueDataSource.Deleting
Dim paramsFromPage As IDictionary = e.InputParameters
Dim queue As New QueueData
If Not paramsFromPage("QueueNamek__BackingField") Is Nothing Then
queue.QueueNamek__BackingField = paramsFromPage("QueueNamek__BackingField")
End If
If Not paramsFromPage("ServerNamek__BackingField") Is Nothing Then
queue.ServerNamek__BackingField = paramsFromPage("ServerNamek__BackingField")
End If
paramsFromPage.Add("queue", queue)
End Sub
The error “The OrderedDictionary is readonly and cannot be modified.” is thrown when an attempt is made to Add to the ordered dictionary.
I found a good workaround to the solution Microsoft suggested. I discovered that while parameters cannot be added or removed programmatically, they can be added declaratively, and the parameters needed for the delete function are added automatically. Also, the parameters that are in the collection can be modified programatically inside the deleting event.
Here is my solution:
I am just wondering if there is a better way to get the data from the cells so that changing the column order does not break this code.