Using The ASP.NET GridView Control

Posted by Mark Benson | Posted in Web Development | Posted on 19-11-2009

0

The display of information from a database is a fairly standard requirement on most websites and, in some development environments, it can take a fair amount of programming to achieve. In ASP.NET, however, it is remarkably easy, thanks to the use of built-in data-bound controls. There are two types of data-bound controls: those which are designed to display multiple records and those which will display one record only. The GridView control, the workhorse of databinding in ASP.NET, falls into the first category. It automatically generates an HTML table and fills it with information from a given data source with each record in the database rendered as a row in the table.

Microsoft Visual Web Developer offers a really easy way to create a GridView control: simply explore the appropriate data source using the database explorer, then drag the appropriate table or view onto the page. This action creates both a DataSource object and a GridView object, both of which can be customised either in Design or Source view. If the listing you wish to display on the page is to be tabular, you may not need to change the default GridView. However, it is more usual that you will want to customize the way in which data is displayed.

In order to customize the GridView, you must ensure that the option to automatically display of all the fields in the database as columns in the HTML table is deactivated. This is done by setting the GridView’s AutoGenerateColumns attribute to False. Secondly, we can display data in a number of different ways. By default information is displayed in a BoundField, meaning that the data is displayed as text. By default, the heading displayed at the top of each column is simply the name of each field in the database. However, you can modify this by changing the HeaderText property of each BoundField element. Another useful property is DataFormatString which allow you to use a format string to control the display of data.

Another useful form of customization is the display of data in a choice of other HTML formats: CheckboxField, RadioButtonField, HyperlinkField, ButtonField and ImageField. The final type of field is CommandField which enables you to display links enabling the user to edit, delete or select rows of data.

For even greater flexibility, the GridView control also provides the TemplateField which allows you to place any HTML content you like in a given column and use databinding statements to embed information from the database as required. Template fields can even contain ASP.NET server controls.

If you would like to learn more about ASP.NET training courses, visit Macresource Computer Training, a UK IT training company offering ASP.NET training courses in London and throughout the UK.

categories: asp.net,web development,microsoft,computers,software

Related posts:

  1. Understanding The For-each Element In XSLT Extensible Stylesheet Language (XSL) is an XML technology which is...
  2. Working With HTML and XHTML in Adobe Dreamweaver CS4 HTML is a markup language used to create web pages...
  3. XML Offers Neutral And Platform Independent Encapsulation Of Your Data Extensible Mark-up Language (XML) has very quickly established itself as...
  4. Mastering The Essentials Of XML Schema XML schema definition languages are based on the recommendations of...
  5. Creating Hyperlinks In Adobe Dreamweaver Most Dreamweaver training courses will show you how to create...

Related posts brought to you by Yet Another Related Posts Plugin.

Write a comment

Anti-Spam Protection by WP-SpamFree