First off, the code-behind model has changed. In the @Page directive, accessing your code behind is accomplish via the CodeFile attribute instead of the Code behind or Src attribute. Also much of the used to DataGrid properties have changed, as seen below:
|
.NET 1.1 DataGrid
|
.NET 2.0 GridView
|
|
CurrentPageIndex
|
PageIndex
|
|
OnPageIndexChanged
|
OnPageIndexChanging
|
|
OnSortCommand
|
OnSorting
|
|
DataKeyField
|
DataKeyNames
|
|
SelectedItemStyle
|
SelectedRowStyle
|
|
ItemStyle
|
RowStyle
|
|
TemplateColumn
|
TemplateField
|
|
BoundColumn
|
BoundField
|
|
DataGrid.Items
|
GridView.Rows
|
|
DataGridItem
|
GridViewRow
|
|
DataGridItem (ItemIndex)
|
GridViewRow (RowIndex).Value
|
|
DataGridPageChangedEventArgs
|
GridViewPageEventArgs
|
|
DataGridSortCommandEventArgs
|
GridViewSortEventArgs
|
The CurrentPageIndex which gets or sets the index of the currently displayed page is now simply PageIndex. Setting up paging and sorting in the Gridview has changed from the OnPageIndexChanged and OnSortCommand methods to OnPageIndexChanging and OnSorting, respectively. The primary key field for the items displayed in the GridView has also changed from DataKeyField to DataKeyNames property.
Setting up row colors on the grid is no more SelectedItemStyle or ItemStyle but rather SelectedRowStyle and RowStyle. I guess this makes more sense since it is a row, anyway. The TemplateColumn class that displays custom content in a data-bound control is now TemplateField, and its partner the BoundColumn which represents a field that is displayed as text in a data-bound control is now called BoundField.
Next, in our code-behind, .NET 2.0 utilizes a new language feature known as a Partial. A Partial class is just that, a partial, incomplete definition of the class or structure. So all that is included in the partial class in only the code needed, such as event handlers and the like. .NET infers the control instances and it derives the events bound from the .aspx file during compilation. Notice in the code behind I didn’t have to declare the GridView or the OutputMsg controls there, as I did in the DataGrid version, neither did I need to include most of the Imports statements that were there before!
Another change in the framework went to the RegisterClientScriptBlock method, this now obsolete method needs to be ClientScript.RegisterClientScriptBlock (Type type, string key, string script) or in our code ClientScript.RegisterClientScriptBlock (Me.GetType(),”clientScript”, jsScript.ToString()).
As for implementing custom paging, this also has changed its class wording from DataGridPageChangedEventArgs to GridViewPageEventArgs.
In Short the main diffrence betbeen GridView and DataGrid is:
Sorting: In DataGrid code requires to handle the SortCommand event and rebind grid required. In case of GridView no additional code required.
Paging: In DataGrid requires code to handle the PageIndexChanged event and rebind grid required. In case of GridView no additional code required. It also supports customized appearance.
Data binding: Like GridView DataGrid cannot bind with new datasource control in ASP.NET 2.0. Updating data: DataGrid requires extensive code to update operation on data. GridView requires little code. Code like exceptions handling for database part.
Events: GridView supports events fired before and after database updates. In DataGrid less events supported as compared to GridView.