hi I have seen a couple of answers for this question but i have a peculiar case. I want to control what displays on an ASP.NET web form with Grid view control when user clicks on a drop down in the code behind. Like this:
你好,我看到了一些关于这个问题的答案,但是我有一个特殊的情况。我想控制在ASP中显示的内容。当用户单击代码后面的下拉菜单时,带有网格视图控件的NET web表单。是这样的:
If ddlProducts.SelectedValue <> "-1" Then
gvCategories.DataSource = obj.getAll().Where(Function(c) c.productId = Integer.Parse(ddlProducts.SelectedValue)).Skip(0).Take(10)
gvCategories.DataBind()
On using ObjectDatasource, I get an error-
在使用ObjectDatasource时,我得到一个错误-
Both DataSource and DataSourceID are defined on 'gvCategories'. Remove one definition.
However, i need to do filtering of a list in code behind and can only set it to Datasource NOT DatasourceID. All of them emphasize no need for code behind. How do i go about it. Please pardon me if it has been answered but i failed to see it probably because i was in a hurry. Thank you.
但是,我需要对后面的代码中的列表进行过滤,并且只能将它设置为Datasource而不是DatasourceID。所有这些都强调不需要后面的代码。我该怎么做呢?如果有人回答了,请原谅,我可能是赶时间,所以没看见。谢谢你!
1 个解决方案
#1
1
You CAN filter a list using the ObjectDataSource
, you do it by adding a new SelectParameter
to it and somehow (programatically for example) passing the value of the parameter. Then, the value is passed to your data provider class (the one the ObjectDataSource
asks for the data) so you can use it in querying the data source.
您可以使用ObjectDataSource来过滤一个列表,您可以通过向它添加一个新的SelectParameter来实现它,并且以某种方式(例如编程)传递参数的值。然后,将该值传递给您的数据提供程序类(ObjectDataSource要求提供数据的类),以便您可以在查询数据源时使用它。
#1
1
You CAN filter a list using the ObjectDataSource
, you do it by adding a new SelectParameter
to it and somehow (programatically for example) passing the value of the parameter. Then, the value is passed to your data provider class (the one the ObjectDataSource
asks for the data) so you can use it in querying the data source.
您可以使用ObjectDataSource来过滤一个列表,您可以通过向它添加一个新的SelectParameter来实现它,并且以某种方式(例如编程)传递参数的值。然后,将该值传递给您的数据提供程序类(ObjectDataSource要求提供数据的类),以便您可以在查询数据源时使用它。