Datagrid web control in dot net
The DataGrid Web Control
The DataGrid Web control was designed to render data into an
HTML table tag, as was shown in figure
That is, for each row in the DataGrid's DataSource, an HTML table row
(tr) is added, and for each column in each row a table column cell is
added (td).
The DataGrid declaration shown in line 29 of code image was the DataGrid
in its simplest form: simply displaying all the rows and columns in the
DataSource using the default formatting options. code does not show is
the DataGrid's rich set of capabilities, which include the following:
-
Custom formatting of the columns from the DataSource.
-
Customizing the appearance of the DataGrid.
-
Allowing the user to sort the results of the DataGrid.
-
Providing pagination support, so that the user can page through the DataGrid's results.
-
A means to edit the data within the DataGrid.
Many of the features listed here and more will be covered later
in the book. In this section, the only feature we'll examine in any detail is
the first one. We will also discuss some of the features of the DataGrid that
are not present in the DataList or Repeater.
Specifying the Columns to Display
the DataGrid
will display all fields in the
DataSource in the order they appear by default. However, there might be
times when you only want to display a subset of the fields in the
DataSource, or you want them to appear in a different left-to-right
ordering. The AutoGenerateColumns property of the DataGrid class
indicates whether all the DataSource's fields will be automatically
added to the DataGrid; by default this property is set to True.
If you want to specify what fields should appear in the
DataGrid Web control, you should first make sure that the
AutoGenerateColumns property is set to False and then add a
Columns tag that explicitly lists the fields that you want to
appear.
NOTE
If you forget to set the AutoGenerateColumns property
to False, but still supply a Columns tag, all of the
DataSource's fields will be displayed in the DataGrid, along with
whatever fields you specify in the Columns tag.
You can use the BoundColumn control to explicitly add a column
to the Columns tag. The vital property of the BoundColumn control is
the DataField property, which specifies the column name in the
DataSource that you want to display. If this is not quite clear,
hopefully an example will help!
—the only change
is in the DataGrid declaration. Rather than having the DataGrid automatically
create its columns from the 
0 comments:
Post a Comment