DCSIMG
ASP.Net QueryExtender Control and DomainDataSource - Guy Burstein's Blog

Guy Burstein's Blog

Developer Evangelist @ Microsoft

News

Guy Burstein The Bu

Disclaimer
Postings are provided 'As Is' with no warranties and confer no rights.

Guy Burstein LinkedIn Profile

TwitterCounter for @bursteg

Links

Articles

Blogs I Read

ASP.Net QueryExtender Control and DomainDataSource

ASP.Net QueryExtender Control and DomainDataSource

ASP.Net QueryExtender DomainDataSourceJust another post about .Net RIA Services with Silverlight and ASP.Net. Previously, I wrote about Using DomainDataSource in ASP.Net and ASP.Net DomainDataSource with Select Parameters. In this post I am talking about the new ASP.Net QueryExtender Control, that applies additional filtering to the DomainDataSource. It does that by an additional expression to the expression tree that the DomainDataSource generates before hitting the DomainService with the query.

You can download the full source code for this sample: QueryExtender Sample.zip

To use the ASP.Net QueryExtender control, you first need to add a reference to Microsoft.Web.Extensions.dll (can be found at: c:\Program Files\Microsoft SDKs\RIA Services\v1.0\Libraries\Server\ folder).

Then, register the its namespace with a tag prefix at the top of the page:

<%@ Register TagPrefix="asp"

  Namespace="Microsoft.Web.Data.UI.WebControls"

  Assembly="Microsoft.Web.Extensions" %>

And now we can add the QueryExtender control to target the customersDataSource.

<asp:DomainDataSource ID="customersDataSource" ...>

</asp:DomainDataSource>

<asp:QueryExtender runat="server" TargetControlID="customersDataSource">

</asp:QueryExtender>

The QueryExtender control takes a collection of DataSourceExpressions. There are several of those in the same assenbly:

  • OrderByExpression
  • MethodExpression
  • PropertyExpression
  • RangeExpression
  • SearchExpression
  • and also CustomExpression.

To use any of those expressions, we’ll have to register another tag prefix with their namespace:

<%@ Register TagPrefix="asp"

  Namespace="Microsoft.Web.Data.UI.WebControls.Expressions"

  Assembly="Microsoft.Web.Extensions" %>

Lets filter a list by customers name. We’ll add a TextBox that will contain the search term:

<asp:TextBox runat="server" ID="txtSearch" />

and then add the expression, and bind it to a the control’s value.

<asp:QueryExtender runat="server" TargetControlID="customersDataSource">

  <asp:SearchExpression SearchType="Contains" DataFields="Name">

    <asp:ControlParameter ControlID="txtSearch" />

  </asp:SearchExpression>

</asp:QueryExtender>

If we now run the application, we can filter by the customer name.

ASP.Net QueryExtender DomainDataSource

Enjoy!

Comments

Brad Abrams said:

A few more great posts on .NET RIA Services over the last week.. Christoph had a great post on Customize

# April 14, 2009 4:45 PM

.Net Code Library said:

Link Round up on .NET RIA Services

# April 14, 2009 10:30 PM

All About Data said:

Today I attended TechED-09. Here are the updates from the sessions I attended and some of the interesting

# May 13, 2009 8:55 PM

Link Round up on .NET RIA Services (April 13th) | rapid-DEV.net said:

Pingback from  Link Round up on .NET RIA Services (April 13th) | rapid-DEV.net

# June 18, 2009 8:43 AM

jv9 said:

Afewmoregreatpostson.NETRIAServicesoverthelastweek..

Christophhadagreatposton

# June 19, 2009 6:34 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: