I was using a ObjectDataSource to generate a listing including paging. The ObjectDataSource used the GetItems method of my usercontrol. See this previous post. This construction works great. But now I needed to do some custom filtering in the GetItems method based on a property of the usercontrol. At first I tried to use the property directly in the GetItems method, this didn’t work the property the property returned NULL. After a small search on the internet I found the following blog post.
The solution is to dynamically add a Selectparameter that will be passed to the GetItems method. You can dynamically add Selectparameters at the OnSelecting event of the asp:ObjectDataSource, like this:
[code language=’c#’]
[/code]
And in you codebehind:
[code language=’c#’]
protected void odsListing_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
{
e.InputParameters[“ListingDataSourceId”] = YourUsercontrolProperty;
}
[/code]
Now you can use YourUsercontrolProperty in the Select method of your ObjectDataSource.
[code language=’c#’]
public Sitecore.Collections.ItemList getItems(string myProperty)
{
// Your selection logica
// You can use the string myProperty for filtering
}
[/code]
Hope it helps.