Wrox Programmer Forums
|
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 22nd, 2006, 03:55 PM
Authorized User
 
Join Date: Dec 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default Search Function and User Controls

Hi, I posted the same question in the ASP.NET 2.0 Professional forum but thought that this forum might be more appropriate since we're following this book.

I implemented a search functionality to a website. That website was developed using a 3-layers architecture as described in Bellinaso's Problem - Design - Solution.

I use a custom control ProductListings.ascx to show the results. Basically, the Recherche class take a string and return a List<Product>. Then the GridView use that List<Product> to show all the results found by the search.

Code:
<asp:ObjectDataSource 
    ID="objRecherche"
    runat="server"
    SelectMethod="SmartSearch" 
    TypeName="SiteWeb.BLL.Services.Recherche">
    ...

<asp:GridView 
    ID="GridView1" runat="server"
    DataSourceID="objRecherche"
    ...
What we want to add is a way to add more information than only the results via a GridView. For example, we want to print the keywords that were used to search for these products, the time taken to process the search, a special message when there is no product.

The Recherche class does more than just pass the search string to the DAL. It will take a string such as "le ski de fond", cut it into 4 words and remove "le" and "de" because they're article. So it will pass ["ski", "fond"]. I want to print that on the result page so the user knows "le" and "de" were not taken into account.

My idea was to add properties (keywords, timeTaken) inside the Recherche object that can be set during the algorithms. Then inside the control, get those properties and print whatever I want before the GridView using either another control or just a Literal.

So, my question is "how do I do this?" and if it's not possible, "what should be done instead?" I tried to do this in the control but it didn't work:

Code:
<asp:Literal runat="server" Text='<%# Test() %>' />

protected string Test()
{
  return ((Recherche)objRecherche).MyProperty;
}
Thanks



 
Old December 24th, 2006, 01:42 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 917
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Did you try this with a label control?

Did you view the page source at runtime to see what was rendered?

Try it like this first to see if that works:

protected string Test()
{
  return "test";
}

Eric


 
Old December 24th, 2006, 03:38 PM
Authorized User
 
Join Date: Dec 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you Eric. Of course that would work. What doesn't work is we cannot cast an ObjectDataSource to our BLL object.

Our problem is that there is no way to get the Recherche object that was used as an ObjectDataSource because it was instanciated declaratively in the ASCX file.

 
Old January 8th, 2007, 11:00 AM
Authorized User
 
Join Date: Dec 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm posting this message in case it can be of help to anybody searching for a similar solution.

Our solution was to 1) Instanciate our object in the code-behind file of the aspx page. 2) Get the GridView of our control by using the FindControl() method. 3) Bind the instanciated object as the DataSource of the GridView. Doing that permit us to have our BLL object with the necessary info. The drawback is that the Control is not self-contained. Everyone that wants to use the control must use a similar procedure to bind the DataSource.

Note that since the DataSourceId of the control is not set, we had to manually implement the page change method into the code-behind of the control because it would throw an exception about PAGE INDEX CHANGING everytime we clicked on the 1 2 3 4 5 ... links.

Code:
protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
   gridView.PageIndex = e.NewPageIndex;
   gridView.DataBind();
}





Similar Threads
Thread Thread Starter Forum Replies Last Post
User controls' content: Chapter 2 User Controls AGS BOOK: Professional ASP.NET 2.0 Server Control and Component Development ISBN: 978-0-471-79350-2 10 July 26th, 2007 05:36 AM
Search Function and User Controls hpox ASP.NET 2.0 Professional 0 December 22nd, 2006 02:27 PM
AJAX Use Search with HTMl controls and Datagrid Nikhil1978 Access ASP 0 December 27th, 2005 02:25 AM
Search All Controls donnie_darko1983 ASP.NET 2.0 Basics 1 April 13th, 2005 01:41 PM
Search Controls on a Form donnie_darko1983 ASP.NET 1.0 and 1.1 Basics 2 April 12th, 2005 05:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.