Question

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:

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-

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top