What is GridVIew Control in Asp.Net c#

GRIDVIEW DATA CONTROL



The Gridview control is the successor to the DataGrid and extends it in a number of ways.

It provides more flexibility in displaying and working with data from your database in comparison with any other controls.


The Gridview control enables you to connect to a datasource and display data is tabular format


With this Gridview control, you could display an entire collection of data, easily add sorting and paging, and perform inline editing.


In addition to just displaying data, the Gridviewcan be used to edit and delete the displayed data as well.


The Gridview comes with a pair of complementary view controls:


1. DetailsView 

2. FormView.

Its properties like BackColor, ForeColor, BorderColor, BorderStyle, BorderWidth, Height etc. are implemented through style properites of <table> tag.


the GridView control reflected against the fields of the data records returned by SqlDataSource in order to dynamically generate the columns of the grid. You can also specify explicit column fields to display by adding DataControlFields  objects to the GridView's Columns collection.




Behavior Properties of the GridView Control
AllowPagingtrue/false. Indicate whether the control should support paging.
AllowSortingtrue/false. Indicate whether the control should support sorting.
SortExpressionGets the current sort expression (field name) that determines the order of the row.
SortDirectionGets the sorting direction of the column sorted currently (Ascending/Descending).
DataSourceGets or sets the data source object that contains the data to populate the control.
DataSourceIDIndicate the bound data source control to use (Generally used when we are using SqlDataSource or AccessDataSource to bind the data, See 1st Grid example).
AutoGenerateEditButtontrue/false. Indicates whether a separate column should be added to edit the record.
AutoGenerateDeleteButtontrue/false. Indicates whether a separate column should be added to delete the record.
AutoGenerateSelectButtontrue/false. Indicate whether a separate column should be added to selecat a particular record.
AutoGenerateColumnstrue/false. Indicate whether columns are automatically created for each field of the data source. The default is true.
Style Properties of the GridView Control
AlternatingRowStyleDefines the style properties for every alternate row in the GridView.
EditRowStyleDefines the style properties for the row in EditView (When you click Edit button for a row, the row will appear in this style).
RowStyleDefines the style properties of the rows of the GridView.
PagerStyleDefines the style properties of Pager of the GridView. (If AllowPaging=true, the page number row appears in this style)
EmptyDataRowStyleDefines the style properties of the empty row, which appears if there is no records in the data source.
HeaderStyleDefines the style properties of the header of the GridView. (The column header appears in this style.)
FooterStyleDefines the style properties of the footer of GridView.
Appearance Properties of the GridView Control
CellPaddingIndicates the space in pixel between the cells and the border of the GridView.
CellSpacingIndicates the space in pixel between cells.
GridLinesBoth/Horizontal/Vertical/None. Indicates whether GrdiLines should appear or not, if yes Horizontal, Vertical or Both.
HorizontalAlignIndicates the horizontal align of the GridView.
EmptyDataTextIndicates the text to appear when there is no record in the data source.
ShowFooterIndicates whether the footer should appear or not.
ShowHeaderIndicates whether the header should appear or not. (The column name of the GridView)
BackImageUrlIndicates the location of the image that should display as a background of the GridView.
CaptionGets or sets the caption of the GridView.
CaptionAlignleft/center/right. Gets or sets the horizontal position of the GridView caption.
State Properties of GridView Control
ColumnsGets the collection of objects that represent the columns in the GridView.
EditIndexGets or sets the 0-based index that identifies the row currently to be edited.
FooterRowReturns a GridViewRow object that represents the footer of the GridView.
HeaderRowReturns a GridViewRow object that represents the header of the GridView.
PageCountGets the number of the pages required to display the reocrds of the data source.
PageIndexGets or sets the 0-based page index.
PageIndexGets or sets the number of records to display in one page of GridView.
RowsGets a collection of GridViewRow objects that represents the currently displayed rows in the GridView.
DataKeyNamesGets an array that contains the names of the primary key field of the currently displayed rows in the GridView.
DataKeysGets a collection of DataKey objects that represent the value of the primary key fields set in DataKeyNames property of the GridView.
Events associated with GridView Control
PageIndexChanging, PageIndexChangedBoth events occur when the page link is clicked. They fire before and after GridView handles the paging operation respectively.
RowCancelingEditFires when Cancel button is clicked in Edit mode of GridView.
RowCommandFires when a button is clicked on any row of GridView.
RowCreatedFires when a new row is created in GridView.
RowDataBoundFires when row is bound to the data in GridView.
RowDeleting,RowDeletedBoth events fires when Delete button of a row is clicked. They fire before and after GridView handles deleting operaton of the row respectively.
RowEditingFires when a Edit button of a row is clicked but before the GridView hanldes the Edit operation.
RowUpdating, RowUpdatedBoth events fire when a update button of a row is clicked. They fire before and after GridView control update operation respectively.
Sorting, SortedBoth events fire when column header link is clicked. They fire before and after the GridView handler the Sort operation respectively.



0 comments:

Post a Comment