修改ObjectDataSource删除参数时出现问题
我正在尝试向 ObjectDataSource 的删除事件添加一个参数,如下面来自 msdn 的示例所示。我为 ObjectDataSource 的删除事件生成了一个事件处理程序,并且它具有与示例中相同的签名,但是,当我尝试像示例中那样清除 paramsFromPage 时,我收到一条错误,指出 paramsFromPage 是只读的。我需要在其他地方改变什么吗?
此示例来自以下 msdn 页面:
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
编辑: 以下是我的代码
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
错误“OrderedDictionary 是只读的,无法修改。”当尝试添加到有序字典时抛出该错误。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了 Microsoft 建议的解决方案的一个很好的解决方法。我发现虽然不能以编程方式添加或删除参数,但可以以声明方式添加它们,并且会自动添加删除功能所需的参数。此外,可以在删除事件内以编程方式修改集合中的参数。
这是我的解决方案:
我只是想知道是否有更好的方法从单元格中获取数据,以便更改列顺序不会破坏此代码。
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.