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


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


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


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:


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