Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I had the same problem as you. Most examples of linqdatasource, ilustare the WhereParameters > controlparameter functionality which is cool but not that powerful. </p> <p>The answer is simple: Use a LinqDataSource and just implement the "onselecting" event pass whatever kind of data you wish. </p> <p>Here is a short example with full filtering-paging-ordering capabilities (also note that the populated sql is optimal and only requests top 10 records every time) </p> <p><strong>ASPX:</strong> </p> <pre><code>&lt;asp:TextBox ID="txtLastName" runat="server"&gt;&lt;/asp:TextBox&gt; &lt;asp:Button ID="btnFilter" runat="server" Text="Filter" onclick="btnFilter_Click"/&gt; &lt;asp:LinqDataSource ID="LinqDataSource1" runat="server" onselecting="LinqDataSource1_Selecting"&gt; &lt;/asp:LinqDataSource&gt; &lt;asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="LinqDataSource1"&gt; &lt;Columns&gt; &lt;asp:BoundField DataField="FirstName" HeaderText="FirstName" ReadOnly="True" SortExpression="FirstName" /&gt; &lt;asp:BoundField DataField="MiddleName" HeaderText="MiddleName" ReadOnly="True" SortExpression="MiddleName" /&gt; &lt;asp:BoundField DataField="LastName" HeaderText="LastName" ReadOnly="True" SortExpression="LastName" /&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; </code></pre> <p><strong>CODEBEHIND:</strong></p> <pre><code> protected void LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e) { var ctx = new LinqDataSource.DBDataContext(); IQueryable&lt;Customer&gt; customers = ctx.Customers; if (!String.IsNullOrEmpty(txtLastName.Text)) customers = customers.Where ( c =&gt; c.LastName.Contains(txtLastName.Text)); e.Result = customers; } protected void btnFilter_Click(object sender, EventArgs e) { GridView1.DataBind(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload