Using The ASP.NET GridView Control

Displaying information on a web page which comes from a database is a fairly standard requirement on most websites and, in some development environmen...


Displaying information on a web page which comes 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.

In Microsoft Visual Web Developer, you can create a Gridview by simply exploring the appropriate data source using the database explorer then dragging 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.

Naturally, you do not have to display all of the fields in the database in the HTML table generated by the Gridview. The GridView’s AutoGenerateColumns attribute should be set to False (which it is by default). Additionally, 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.

Where appropriate, you can also display 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, an independent computer training company offering ASP.NET training courses at their central London training centre.

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

Related posts:

  1. How To Use The ASP.NET GridView Control The display of information from a database is a fairly...
  2. Using Looping Syntax In XSLT Extensible Stylesheet Language (XSL) is an XML-related technology which is...
  3. Creating HTML and XHTML With Adobe Dreamweaver HTML is a markup language used to create documents designed...
  4. XML Offers Neutral And Platform Independent Encapsulation Of Your Data Extensible Mark-up Language (XML) has quickly established itself as a...
  5. Overview of XML Technologies Core XML...

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

Leave a Reply

Spam Protection by WP-SpamFree