Contents

Introduction

Part I: Grids, Editors, Navigation, and Controls

Chapter 1: Programming with the ASPxGridView

Understanding How Ajax Delivers Real Performance to the ASPxGridView

Binding and Editing Data in the ASPxGridView

Filtering Data

Grouping and Sorting Data

Creating and Using Summary Values

Managing the Grid’s Appearance

Summary

Chapter 2: Advanced ASPxGridView Computing

Storing Changes

Enabling Callback Compression

Catching Callback Errors Using an ASPxHttpHandlerModule

Binding the ASPxGridView to an ArrayList or Collection

Using Unbound Columns

Implementing a Custom Sort

Exporting Grid Data

Using Master and Detail Grids

Saving User Customizations with Cookies

Programming Client-Side Events

Using Custom Script Properties

Enabling Horizontal Scrolling

Displaying Images Directly from a Database in a Template Region

Summary

Chapter 3: Using the ASPxTreeList, ASPxDataView, and ASPxNewsControl

Displaying Data in Tree Views

Introducing the ASPxDataView

Displaying News and Product Headlines in a Web Page

Summary

Chapter 4: Adding SiteMaps, Navigation, and Pop-Up Dialog Boxes

Implementing a Navigation Bar

Facilitating Social Networking with the ASPxCloudControl

Creating a Sitemap with XML and the ASPxSiteMapControl

Using Modal Dialogs in ASP.NET

Summary

Chapter 5: Implementing a Menu and Tabbed Controls

Building Menus with the ASPxMenu

Incorporating Pop-Up Menus into Your Web Application

Creating Tabbed Views

Summary

Chapter 6: Managing Scheduled Items and Using Gauges

Scheduling Calendar Events

Using the ASPxGaugeControl

Summary

Part II: Data Sources, JavaScript, CSS, and Themes

Chapter 7: Using the Data That Makes Sense for Your Solution

Using an XpoDataSource

Enabling ServerMode for High Performance Applications

Generating a Database Dynamically with XPO

Summary

Chapter 8: Implementing Data Solutions with the ASPxPivotGrid

Transforming Relational Data into an ASPxPivotGrid

Exporting Data to Create Crosstab Reports

Binding to an OLAP Cube

Using an ASPxPivotGrid as a WebChartControl’s Data Source

Grouping Axis Values

Arranging Values Hierarchically

Calculating Totals

End-User Data Filtering

Sorting Data and Displaying Top or Bottom Values

Using the Drill-Down Window

Summary

Chapter 9: Using the ASPxHtmlEditor

Managing ASPxHtmlEditor Features

Defining a Custom ASPxHtmlEditor Toolbar

Applying Custom Styles (CSS)

Enabling Spell Checking

Summary

Chapter 10: Using Themes, CSS, and JavaScript for Customizations and Enhancements

Defining and Managing Style Information

Using Skins and Themes

Making the Most of JavaScript

Summary

Part III: Ajax, Charting, Reporting, and Cloud Computing

Chapter 11: Asynchronous Computing for ASP.NET

Controlling Asynchronous Behavior with a Timer

Displaying Multimedia Content

Summary

Chapter 12: Adding Charts and Graphs to Your Applications

The Vernacular

Creating a Chart

Medium Trust

Real-time Updates

Runtime Visual Effects

Summary

Chapter 13: XtraReports For the Web

Creating a Tabular Report

Using the SQLDataAdapter as a DataSource

Using an IBindingList as a DataSource

Using XML as a DataSource

Conditional Report Bands

Master-Detail Report

Drill-Through Report

Label Report

Mail Merge Report

Caching the Report

Parameterized Stored Procedure Report

Combining Multiple Reports

End-User Report Designer

Summary

Appendix A

Index

Professional DevExpress™ ASP.NET Controls

Published by
Wiley Publishing, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256

www.wiley.com

Copyright © 2010 by Wiley Publishing, Inc., Indianapolis, Indiana

Published by Wiley Publishing, Inc., Indianapolis, Indiana

Published simultaneously in Canada

ISBN: 978-0-470-50083-5

Manufactured in the United States of America

10 9 8 7 6 5 4 3 2 1

No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions.

Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent professional person should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Web site may provide or recommendations it may make. Further, readers should be aware that Internet Web sites listed in this work may have changed or disappeared between when this work was written and when it is read.

For general information on our other products and services please contact our Customer Care Department within the United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.

Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books.

Library of Congress Control Number: 2009930063

Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Wrox Programmer to Programmer, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. DevExpress is a trademark of Developer Express, Inc. All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book.

For Alex and Noah

About the Authors

Paul Kimmel is a technical Evangelist for DevExpress and loving every minute of it. Paul started programming in 1988 when Donald Gardener and Mike Groher let him write some Databus code and has been writing code ever since. Paul has twenty plus years of experience writing software, writing books on object-oriented languages and UML, presenting at national conferences and local user groups, and is the co-founder of two .NET User Groups (Greater Lansing Area .NET User Group in Flint and East Lansing, Michigan). Paul is a five-time Microsoft MVP and the VB Today columnist for codeguru.com and is frequent contributor to InformIT.com, developer.com, devsource.com, and Dr. Dobbs Journal.

Julian Bucknall is the Chief Technology Officer for DevExpress, a software company that writes some great controls and tools for .NET and Delphi. He is responsible for technology oversight at DevExpress. Julian is the author of the Tomes of Delphi: Algorithms and Data Structures from WordWare Publishing, Inc, the author of blog.boyet.com and the ctodx blog at DevExpress.

Julian is an ex-Brit, residing in Colorado with his beautiful wife and considers himself a programmer by trade, an actor by ambition, and an algorithm guy by osmosis as well as a contributor to PCPlus, the UK’s premier technology magazine.

Joe Kunk received his B.S. in Computer Science from Michigan State University in 1984 and has worked as a business analyst, software developer, manager, and entrepreneur in the fields of education, government, and IT consulting. Joe is a Microsoft MVP, President of the Greater Lansing User Group for .Net, Board Member of the Lansing IT Council, Senior Consultant at A. J. Boggs & Company, and co-founder of Listen IT Solutions, LLC. Joe lives in Okemos, Michigan and enjoys the many events at the MSU Wharton Center for Performing Arts, speaking about technology at user groups and regional conferences, and family time with his wife and two daughters.

Credits

Acquisitions Editor
Paul Reese

Project Editor
Adaobi Obi Tulton

Technical Editor
Doug Parsons

Senior Production Editor
Debra Banninger

Copy Editors
Susan Christopherson
Kim Cofer

Editorial Director
Robyn B. Siesky

Editorial Manager
Mary Beth Wakefield

Production Manager
Tim Tate

Vice President and Executive Group Publisher
Richard Swadley

Vice President and Executive Publisher
Barry Pruett

Associate Publisher
Jim Minatel

Project Coordinator, Cover
Lynsey Stanford

Proofreader
Nancy Carrasco
Carrie Hunter, Word One

Indexer
Robert Swanson

Cover Image
PhotoDisc/Punchstock

Acknowledgments

The more I write the more I am indebted to the people who have helped me. These are my acknowledgment of thanks and gratitude for those people.

Thanks to Ray Navasarkian at DevExpress. Without Ray’s creative insight, support, and drive this book could not have happened. Ray is by far one of the most driven and fun bosses I have ever had the pleasure of working for.

I would also like to thank Joe Kunk, Gary Short, Julian Bucknall, and Kevin White. The goal was to get the book done in time for PDC and without their extensive support and co-authorship I never would have made it. Joe did a tremendous job on the XtraReports parts, Gary helped with examples on XPO, and Julian pitched in on chapters, editing, and a sound understanding of the book writing and publishing business. Kevin had to listen to all of my whining, which in all likelihood was the worst job but the often most helpful. Thanks Kevin.

A special thanks to Adaobi Obi Tulton, Jim Minatel, and all of the fantastic and patient people at Wrox. This is my second time working with Adaobi and each time gets to be more rewarding.

Thanks to all of the developers, evangelists, and managers at DevExpress who provided timely and invaluable feedback, including Platon Fedorovsky, Roman Eremin, Mike “Falcon” Rozhdestvenskiy, Mehul Harry, Erika Day, Jeff Cosby, Mark Miller, Oliver Sturm, Gary Short, Kevin White, Julian Bucknall, Azret Botash, Emil Mesropian, Rachel Hawley, Richard Morris, Andrew Logachev, Dmitry Babayev, and Serge Seleznev. And, of course, thanks to all of the DevExpress designers and developers for creating a tremendous suite of products and software.

Thank you to Alex and Noah Kimmel. They are teenagers now and need less of my time, but every moment with them has been my greatest blessing.

As always I am the first beneficiary of this work. It has been an insightful education, and I am fortunate to have had the opportunity.

Introduction

I like writing because every book is a birth. Books are neat little packages that contain information that has been pulled out of mind stuff, written down, edited and re-edited, printed, and glued together. When I get my author copies there is always a sense of satisfaction at having been part of creating something. Then, I take a deep breath and wait to see what the readers think.

Components and controls are always just one part of application development. Developers have to get requirements, design solutions and databases, and assemble all of the various pieces and then refine the total effort. Writing books and software follow some of the same practices: define, design, implement, debug/edit, ship, and support. In either kind of implementation, whether book or software, sometimes requirements and features make it in and sometimes they don’t.

This book was originally slated at 400 pages. There were so many more features that I wanted to cover that almost 200 additional pages were added. In truth, there were discussions we had internally about how we could have provided more samples and probably produced 1,000 more pages. DevExpress offers many rich products and this book really just focuses on the ASP.NET controls. (A WinForms book could easily cover its own 1,000 pages.)

Although many people participate in the process of a book, writing a book for the most part is about telling a story from one person’s perspective. For this book I looked at all of the products DevExpress offers in the ASP.NET space and tried to cover every single one of them. The ASPxGridView is a widely used product and it got a lot of coverage, but the juicy products like ASPxScheduler, ASPxTreeList, ASPxHTMLEditor, ASPxPivotGrid, XtraCharts, XtraReports, and many more products got extensive coverage. Some of these products even got their own chapters. If you glance at the table of contents you will see that XPO, the ASPxCloudControl, and client-side controls are all covered. There are even sections on general ASP.NET topics like JavaScript, Themes and Skins, and cascading style sheets. Unfortunately, in 600 pages I couldn’t cover everything and some samples that would have been good samples didn’t make it. To that end this book will have a product support page where I (and others I suspect) will be adding updated information for new releases, additional samples, and samples based on your inquiries. As I am sure you have challenges I didn’t think of, if you send inquiries to me at paulk@devexpress.com I will work out a sample, and write a blog or an article as a supplement.

The real purpose of this book is to provide our very important customers with another resource that will help them build great software. Every effort is made to make your development experience intuitive, productive, and fun. However, our products are feature rich and we understand that sometimes it helps to have someone point you in the right direction or provide you with a little guidance. This book is one additional bit of that guidance. If you need more than what is between these pages, just ask.

The first beneficiary of a book is the author. Even authors gain tremendous insight as part of the process of writing. One not so obvious insight is that our dozens of developers can turn out dot releases faster than I can write about all of them. This book was produced against versions 8.3 to 9.1. Just as I finished writing, 9.2 was released and 9.3 will be done by the time you are holding this finished book. As soon as I finish my final edits to the draft, I will be working diligently to create new examples, write about what is new, and updating material in the form of blogs and articles so that information — on 9.2 and 9.3 — will be available in conjunction with this book.

Many people helped this book get published, and I couldn’t have done it without their help. Ownership of the story is mine, and any mistakes are my responsibility. The objective was and is to provide more support and a better customer experience. The real heroes are our developers, and I hope I did some justice to their great efforts.

Part I: Grids, Editors, Navigation, and Controls

Chapter 1: Programming with the ASPxGridView

Chapter 2: Advanced ASPxGridView Computing

Chapter 3: Using the ASPxTreeList, ASPxDataView, and ASPxNewsControl

Chapter 4: Adding SiteMaps, Navigation, and Popup Dialog Boxes

Chapter 5: Implementing a Menu and Tabbed Controls

Chapter 6: Managing Scheduled Items and Using Gauges

1

Programming with the ASPxGridView

This year is the tenth anniversary of my VB Today column for Codeguru.com and Developer.com. (My first article was published in PC World in 1992.) In that time, during which I’ve written hundreds of articles, readers have written to me more about two subjects than any other: keyboard hooking and grid controls.

Low-level keyboard hooks are cool. I started using them with DOS interrupts and C++ in the early 1990s. Grids of data, however, have the more practical and compelling everyday usefulness.

For years now, customers have asked me to make grids do things that they originally did not seem designed to do, including doing complex relationship modeling with grid nesting and performing real-time calculations with solutions that are more like Rube Goldberg machines than algorithms. Although crafting these solutions — sometimes against my better judgment — with nested user controls and hand-written asynchronous callbacks from scratch has been fun, I’m pleased to pass the baton off to the ASPxGridView.

The ASPxGridView is designed to support nesting, the power of Ajax callbacks, tuned performance for small and huge data sets, sorting, grouping, creating summaries, working with themes and skins, and much more. This chapter and the next chapter explore the ASPxGridView. I created the TotalFlight database for the samples used in these chapters because I wanted large amounts of data, but you can easily use Northwind or any other database that has a great deal of data to run the samples. (I used Red Gate Software’s SQL Data Generator 1 to populate the TotalFlight database.)

Understanding How Ajax Delivers Real Performance to the ASPxGridView

A lot of conventional wisdom floats around, including the idea that to get high performance from your Web applications, you need to limit the amount of data you return to the client. Generally, limiting returned data required that each programmer limit possible query results or invent some mechanism for micromanaging high-data-prone controls such as grids. Then, things changed — and they seemed to change pretty quickly even for Internet time. Ajax had arrived.

Now called Ajax (in mixed case), the term AJAX (all uppercase) was coined in 2005. Originally, AJAX was an acronym for Asynchronous JavaScript and XML. AJAX was a derivative of capabilities created in the 1990s, including Internet Explorer’s IFrame and Java Applets, and is based on the ActiveX object XMLHttpRequest, or remote scripting for browsers that don’t support XMLHttpRequest. The term AJAX brought asynchronous callbacks to the general programming community’s attention, and AJAX made controls such as the UpdatePanel accessible to all developers. (These later developments actually happened in 2005 and 2006.) Originally dubbed AJAX for JavaScript, XML, or asynchronous calls, it is now simply referred to as Ajax.

What Does Ajax Do for Web Developers?

Web forms have a life cycle. (Refer to “Appendix A: Understanding How Web Applications Differ from Windows Applications” for more on page life cycles.) When a page is posted back from the client to the server, it goes through the entire life cycle. This life cycle includes rerendering the page, which in turn causes the very visible page flicker users experience. Many times, much of what the user experiences is the result of static content and minor changes based on their interactions with the page; what they pay for with a postback is the re-creation of everything.

Ajax uses callbacks. A callback sends data back to the server, but only the relevant response is returned through the browser. Ajax plumbing literally used to require — as late as 2005 — programmers to inject dynamic JavaScript, wire up event handlers, and manually parse and stuff text returned into the client Web page with more JavaScript. (There are dozens of JavaScript examples throughout the book.) The benefit of employing all this specialized knowledge is that users had a better experience because they paid for data refreshes only when something actually changed on a page. Also, pages seemed to update magically.

You can still use wired-up Ajax with injected script if you want, but it is more error prone and requires great JavaScript authoring and debugging skills. With DevExpress controls and the ASPxGridView, you get the benefit of Ajax without the hassle.

ASPxGridView and Ajax

On top of all the features in the ASPxGridView, including sorting, grouping, filtering, and summaries, the ASPxGridView does three very important things that help you get the highest performance: It uses the database server instead of client-side script to manage data; it manages the client VIEWSTATE block itself by using a smart caching engine rather than sending tons of VIEWSTATE to the client; and it is built using Ajax internally. The UpdatePanel is supported — by setting EnableCallbacks to false — but the UpdatePanel is not required.

Microsoft shipped the UpdatePanel in late 2005 (or 2006). Any control can get some Ajax support with the UpdatePanel.

To demonstrate the ASPxGridView, you can follow the examples in this chapter and the next to build the TotalFlight sample shown in Figure 1-1, which includes a 1,000,000-row result set.

Figure 1-1: You can complete the TotalFlight passenger manifest sample by working through the samples in this chapter and in Chapter 2.

Another feature of the ASPxGridView is the EnableCallbackCompression property. IIS supports compression — a general approach — whereas the ASPxGridView will support compression for the grid if IIS compression is not enabled, a refinement from the general in IIS to the specific compression in the . (Refer to the Appendix A section “Upgrading to IIS 7” for information on enabling IIS compression.) If you set to , the grid checks to see whether the request header contains or — if content encoding is supported by the browser — and compresses the result if supported. You can check the value by using a free tool such as Fiddler (see ) or exploring the value in Visual Studio debug mode.

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!