DrewKBell

I've linked a gridview to my LinqDataSource. All is working fine. I've added a where paramter to the datasource for an ID field. Now what I want to do is set it up to load all records on the initial load. I can put in a parameter and serach fine. I just can't figure out if there is some type of wild card or something special to do for this.

When using a SqlDataSource and stored procedure, I could do either a coalesce or write an if statement in the proc to return all if there is a certain parameter submitted.

- Thanks




Re: LINQ Project General LinqDataSource Where Parameter Return All

DrewKBell

The answer is pretty straight forward (thanks to Scott and his blog).

http://weblogs.asp.net/scottgu/archive/2007/09/07/linq-to-sql-part-9-using-a-custom-linq-expression-with-the-lt-asp-linqdatasource-gt-control.aspx

You can utilize the selecting event of the linqdatasource. Then search how you want using either a stored proc or linq language. Just rebind the grid when you want to use a search button.





Re: LINQ Project General LinqDataSource Where Parameter Return All

chenriks

You can also take advantage of the AutoGenerateWhereClause feature. When true, the Where clause will be automatically generated (using "==" and "AND") from all WhereParameters whose values are not null.

For instance, the following will use no Where clause (returning all rows) when the parameter value is null, and will use Where="CategoryID == @p1" when the parameter value is set:

<WhereParameters>

<asp:ControlParameter Name="CategoryID" ControlID="DropDownList1" Type="Int32" />

</WhereParameters>