我如何设置ObjectDataSource的选择参数在运行时 [英] How do I set up ObjectDataSource select parameters at runtime

查看:159
本文介绍了我如何设置ObjectDataSource的选择参数在运行时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想参数在运行时像这样添加到ObjectDataSource控件:

I'm trying to add parameters to an objectDataSource at runtime like this:

        Parameter objCustomerParameter = new Parameter("CustomerID", DbType.String, customerID);
        Parameter objGPDatabaseParameter = new Parameter("Database", DbType.String, gpDatabase);

        //set up object data source parameters
        objCustomer.SelectParameters["CustomerID"] = objCustomerParameter;
        objCustomer.SelectParameters["Database"] = objGPDatabaseParameter;

在ObjectDataSource控件生命周期的哪个点应该这些参数被添加(什么事件)?此外,一些值从母版页属性来(其中负荷的 的包含ObjectDataSource控件的页面的Page_Load后)。

At what point in the objectDataSource lifecycle should these parameters be added (what event)? Also, some values are coming from a master page property (which loads after the page_load of the page containing the objectDataSource).

推荐答案

它们添加到您要使用操作的事件。例如,如果这些参数是SELECT命令的一部分,然后将它们添加到选择的事件,如果他们需要去的UPDATE命令然后加入他们在更新的事件。

Add them to the event for the operation you are trying to use. For example, if these parameters are part of the SELECT command then add them to the Selecting event, if they need to go with the UPDATE command then add them on the Updating event.

ObjectDataSource控件引发一个事件将执行每次操作前,这时候你可以插入参数(或验证/改变现有参数)。

The ObjectDataSource raises an event before it performs each operation, that's when you can insert parameters (or validate/alter existing parameters).

另外,不要试图修改消耗臭氧层物质本身的参数集合。你想你的参数添加到传递到事件处理程序的ObjectDataSourceSelectingEventArgs。

Also, don't try and modify the parameters collection of the ODS itself. You want to add your parameters to the ObjectDataSourceSelectingEventArgs that is passed to the event handler.

是这样的:

e.InputParameters["CustomerID"] = customerId;
e.InputParameters["database"] = dbName;

这篇关于我如何设置ObjectDataSource的选择参数在运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆