aspxtreme

DataGrid Control Syntax

ASP.NET Syntax   ASP.NET Syntax for Web Controls


The DataGrid control renders the items of a given data source into a table. The records and fields in the data source are displayed as rows and columns in the grid.

Declarative Syntax

For information on the individual members of this class, see DataGrid in the class library.

In addition to its default settings, the DataGrid supports a vatiety of options to customize the layout of the grid and add specific functionality. Authors can control which fields are displayed in the DataGrid control and also allow users to select, edit, sort, and page thru the items in the control.

The following sections describe variations of the syntax used for implementing a DataGrid control on a Web Forms page.

Syntax

The minimum syntax required to implement a DataGrid control is shown below.

<asp:DataGrid runat="server"
   id="accessID"
   DataSource = '<%# DataBindingExpression %>' />

The DataSource property sets the source to a list of values used to populate the items within the control. This property can also be, and in most cases is, set in code.

For an example of using a basic DataGrid control, see Adding DataGrid Controls to a Web Forms Page.

To modify the default look and layout of the grid ( adjust the color, font, borders, spacing, and so on for the grid as a whole ), authors can declaratively set any of the control's member properties within the opening tag.

<asp:DataGrid runat="server"
   id="accessID"
   ...
   propertyName = "propertyValue" />

where propertyName can be any of the following.

Properties for Controlling DataGrid Layout


Property Description
Base properties The properties inherited from the base WebControl class.
AutoGenerateColumns Specifies whether columns will be generated for each bound data field. Set to false when customizing column layout. When not specified, defaults to true.
BackImageUrl The URL of an image to display behind the control.
CellPadding The amount of space, in pixels, between the contents of a cell and the cell's border. When programming, this property is set using Units.
CellSpacing The amount of space, in pixels, between cells. When programming, this property is set using Units.
GridLines How grid lines are displayed between items. Possible values are None, Horizontal, Vertical, and Both. The default is None.
HorizontalAlign The alignment of the rows with respect to surrounding text. Possible values are Left, Center, Right, Justified, and NotSet. The default is NotSet.
ShowFooter true if the footer should be rendered, false otherwise.
ShowHeader true if the header should be rendered, false otherwise.


Books and more ...


Suggested Reading

Need a break ?


More ...
Back to top

Check out related books at Amazon

© 2000-2008 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support aspxtreme