Home > Microsoft .Net Development Tips > ASP.NET Development > Using DataGrid and GridView in ASP.NET 2.0
Win Development Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ASP.NET DEVELOPMENT

Using DataGrid and GridView in ASP.NET 2.0


Ed Tittel, Contributor
12.14.2005
Rating: --- (out of 5)


.NET Essentials Channel
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


Microsoft's Visual Studio Web pages are chock full of good information and examples about how to make effective use of that environment. As such, my job is to report on especially useful or compelling examples of this kind of thing, and to point out where related code for such things resides. This time around, I draw on an article by Dino Esposito that deals with using the DetailsView and FormView controls in ASP.NET 2.0 that work with DataGrid and GridView to enable easy construction of attractive, readable, data-driven record displays.

As it happens, though ASP 1.x included some powerful and usable data-bound controls, none of them were designed to manage views of individual records. Building master/detail views typically means allowing users to select individual records from a comprehensive records list (the master part) and then to display and manipulate the contents of a single selected record (the detail part).

The problem with ASP.NET 1.x was that, while it could show individual record fields using the DataGrid, GridView and other controls, it couldn't really manage a master/detail view or provide record-view control without buying third-party tools or building equivalent functionality on your own.

That's changed in ASP.NET 2.0. Microsoft now offers new controls that support single-record views. In particular, FormView and DetailsView controls now work with DataGrid and GridView to make it easy to create master/detail views.

With DataGrid and GridView, you see, for example, a list of company records on the left-hand side (the master view) and information about one particular record on the right hand side (the details view). You can edit the information in the details pane, but...


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google



RELATED CONTENT
ASP.NET Development
How to use jQuery to solve Javascript browser compatibility problems
How to write an out-of-browser Silverlight 3 application in 3 steps
Silverlight 3 beta SDK download lets developers try new RIA features
Visual Studio's IntelliSense for jQuery doesn't autocomplete correctly
Dundas Map for .NET kicks up geographic visualization
Return to CodePlex: Into the Sandcastle…
VBScript Tutorial
Use PHP with Visual Studio to create Web sites
Visual Studio Team System Add-ins: Conchango Scrum for Team System and Scrum Dashboard
Visual Studio 2008 and .NET Framework 3.5 SP1 introduces ADO .NET Entity Designer

ASP.NET development best practices
Introduction to ASP.NET's Model View Controller (MVC) Design Pattern
Silverlight, Ajax components require different approach to UI
LINQ Learning Guide: LINQ and Web applications
VB code download home page
VB code: File manipulation downloads
Localization practices for .NET 2.0: It's still about the architecture
Creating custom ASP.NET 2.0 profile providers
.NET development in the trenches
Microsoft developers balancing age-old issues, barrage of new technology
SearchVB.com's Podcast Page

.NET Framework database programming best practices
Windows 7 for developers
Microsoft's Oslo modeling platform, the M language and .NET
Using the Visual Studio 2005 DataSet Designer to build a data access layer
Windows Developments: Product news February 2008
Oracle updates data access components for Visual Studio 2008
Reporting tool now supports Word 2007 and VS 2008
Windows Developments: Product news, January 2008
Choose the right .NET data provider, optimize application performance
Windows Developments: Product news, December 2007
The fallacy of the data layer -- or, a new architectural model for software designs

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
136 browser colors with names  (SearchWinDevelopment.com)
ASP.NET  (SearchWinDevelopment.com)
browser  (SearchWinDevelopment.com)
Document Object Model  (SearchWinDevelopment.com)
domain name  (SearchWinDevelopment.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary


it won't show up in the master view until you click the Update button. That's because the GridView (used for the master view) isn't updated until the DetailsView (used for the details view, naturally) posts changes to the actual record. The way to keep things synchronized, therefore, is to force GridView to refresh its data source any time a detail record is updated -- easy to arrange, because the DetailsView control posts an ItemUpdated event each time an update is processed.

FormView and DetailsView controls are quite similar, but differ in the way they lay out their outputs. FormView permits complete control over the layout and enables easy creation of custom forms with controls to display and edit fields. DetailsView is limited to a strictly 2D table layout with exactly two columns: header and value. You can, however, use templates to customize the value cell, by using the TemplateField class much as you would for a column within a grid control. Thus, for example, you might use a Calendar control to render a date field, and thereby inherit all the mechanics needed to properly format and display date/time information.

DetailsView also provides new ways for ASP.NET 2.0 to handle validation controls. These may apply to required fields, regular expressions, or specific value ranges. Here again, you can use templates for each field you display, adding validator controls within the template. This makes it easy to use whichever combination of validators is needed to screen and filter user input.

Overall, the enhancements that FormView and DetailsView make available are pretty compelling. If you download Esposito's sample code, you'll find numerous illustrations of all these principles put nicely to work, with value- and event-based validation techniques to boot. Definitely worth a look-see!

Ed Tittel is a full-time writer and trainer whose interests include XML and development topics, along with IT Certification and information security topics. E-mail Ed at etittel@techtarget.com with comments, questions, or suggested topics or tools to review.



Rate this Tip
To rate tips, you must be a member of SearchWinDevelopment.com.
Register now to start rating these tips. Log in if you are already a member.




DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Database Programming Solutions - .NET XML, Visual Studio LINQ, ORM .NET
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2000 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts