advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Download the sample application.
Partners & Affiliates
advertisement
advertisement
Average Rating: 5/5 | Rate this item | 3 users have rated this item.
 Print Print
Nested DataGrids Simplify Hierarchical Data Display (cont'd)
Finding Your Orders
The Orders Advanced Search page allows users to locate customers' previous orders and does double duty as an order history report. The search criteria page takes zero or more customer demographics, an optional customer, and a required date range. More relevant is what the page returns:
advertisement


 
Figure 6. Orders Advanced Search Schema: This schema shows the tables and relationships returned by the Orders Advanced Search page.
  • Orders—including order date, customer and shipper.
  • Products related to each Order—including product name and quantity.
  • A count of products ordered for the current customer and current product, for each month in the date range.
The strongly typed dataset that holds the search results is shown in Figure 6. You can find the schema in the download that accompanies this article.

The normalized approach to holding data greatly simplifies displaying it hierarchically in the user interface. Figure 7 shows the loops in the page.

ProductMonthCounts—Where Things Get Interesting
There is a lot going on in the page with five separate multi-record controls nested three levels deep. First, each is bound using a different approach. The outermost loop for products is bound in the code-behind page; the nested loops are bound using data-binding syntax; and the innermost loop, for ProductMonthCounts, is bound in the ItemDataBound event of the nested OrderDetails (products) Repeater.

 
Figure 7. Loops In Search Results: The arrows show the inner and outer loops required to display the hierarchical data.
The innermost loop is the most complex. You have to bind it in the ItemDataBound event primarily because it requires a custom sort order. The custom sorting is required because the database doesn't return months where no products were sold; the middle tier inserts those records. Consequently, the order of records is incorrect in the dataset. The relevant section of code sorts by the FirstDayInMonth field and binds to records that match the current product and customer:

   string strCriteria = String.Format(
     "ProductId={0} AND CustomerID='{1}'", 
     intProductId,
     strCustomerID);
   rptProductCountMonths.DataSource = 
     tdsSearchResults.ProductMonthCounts.Select(
     strCriteria, 
     "FirstDayInMonth");
   rptProductCountMonths.DataBind();
Another interesting aspect of the innermost loop is the code that dynamically sets the background color to a deeper shade depending on the number of orders sold.

   <td style='background-color: <%# GetBgColorFromQuantity(
     (int)((DataRow)Container.DataItem)["Count"], 
     false) %>'> … </td>
GetBgColorFromQuanity() takes a quantity of products sold, computes red, green, and blue values and returns an HTML color with a call to:

   System.Drawing.ColorTranslator.ToHtml(
     System.Drawing.Color.FromArgb(intRed, intGreen, intBlue)
     ); 
This is yet another application of the data-binding syntax.

Even if you don't need to display hierarchical data frequently, a thorough understanding of control hierarchy, data-binding syntax, and events of multi-record controls will empower your code and help you create more robust and maintainable solutions. At first, using nested controls may seem more complicated than the traditional approach of building HTML tables in code, but when you're asked to change your UI the day the application is due, you'll be glad you did.

Page 4 of 4


advertisement
Lee Richardson is founder and Chief Executive Officer of Automated Architecture, Inc., and is the author of the Blue Ink application and the JAG software development methodology. Lee works as a senior consultant for the Headstrong consulting company, specializing in rapid application development technologies. He has nine years of software development experience, is a Microsoft Certified Solution Developer (MCSD), and a Project Management Professional (PMP).
Previous Page: Other Data Binding Syntax Applications  
Page 1: IntroductionPage 3: Other Data Binding Syntax Applications
Page 2: To Normalize or Not to NormalizePage 4: Finding Your Orders
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Win Server ‘08
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES