Add WhereParameters to LinqDataSource in Selecting event

Posted by Steven on Stack Overflow See other posts from Stack Overflow or by Steven
Published on 2010-03-19T01:03:02Z Indexed on 2010/03/19 1:11 UTC
Read the original article Hit count: 471

Filed under:
|
|

I have a repeater using a LinqDataSource as a data source. When a query string is entered, I'd like to filter the results, but ONLY when a query string is entered. If there is no query string, the results should not be filtered, all results should be returned.

I'm trying to add a WhereParameter to my LinqDataSource in the Selecting event of the LinqDataSource, but it's not working. Here's my code:

protected void ldsImages_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
    if (Request.QueryString["id"] != null)
    {
        e.WhereParameters.Add("ImageTypeID", Request.QueryString["id"]);
    }
}

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about c#