Wednesday 15 February 2012

Difference Between DataGrid and GridView

Introduction
The GridView and the DataGrid controls have a different logics.

There is a lot of differnce compatibility between DataGrid and GridView Codes
GridView can bulid pages on mobile devices
DataGrid in  1.x doesn't supports the themes however in 2.0 it perform themes.
The DataGrid in version 2.0 can also render adaptively,
GridView supports the classic bindingbased on the DataSource property.
GridView provides the option for paging ,sorting in easy click of a button however datagrid
required some coding
Grid View Features
· Richer design-time capabilities.
· Improved data source binding capabilities.
· Automatic handling of sorting, paging, updates, and deletes.
· Additional column types and design-time column operations.
· A Customized pager user interface (UI) with the PagerTemplate property.
· Different custom-paging support.
· Different event models.
For Example how the paging index differs
DataGrid
HTML
 <asp:DataGrid ID="DataGrid1" runat="server" OnPageIndexChanged="DataGrid1_PageIndexChanged"
 AllowPaging="true" PageSize="5" OnSelectedIndexChanged="d1_SelectedIndexChanged">
 </asp:DataGrid>   



Codebehind
protected void DataGrid1_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
    {
      DataGrid1.CurrentPageIndex =  e.NewPageIndex  
      BindGrid();// Grid binding method
    } 
GridView
 <asp:GridView ID="GridView1" runat="server" OnPageIndexChanging="DataGrid1_PageIndexChanging"
  AllowPaging="true" PageSize="5" OnSelectedIndexChanged="d1_SelectedIndexChanged">
  </asp:GridView>   
Codebehind
protected void GridView1_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
    {
      GridView1.PageIndex =  e.NewPageIndex  
      BindGrid();// Grid binding method
    }    

It allows for the mix both data bound and unbound, virtual columns in the GridView.
It has a special virtual mode allowing for the display of more than 100.000 rows without
a huge performance hit.
Individual columns, rows, cells or an entire data source can easily be styled.
private void InsertDataGridColumn()
{
DataSet dataset = new DataSet();
DataGridTableStyle TStyle = new DataGridTableStyle();
DataTable table = dataset.Tables["Student"];
TStyle .GridColumnStyles[0].MappingName ="Stid"
TStyle .GridColumnStyles[0].HeaderText = "Student ID";
TStyle .GridColumnStyles[0].Width = 150;
DataGrid1.TableStyles.Add(TStyle );
}
The above example is used for DataGrid TableStyle.
DataGridView control designing operations are done through the IDE design layout window via drag and drop.
We can extend the DataGridView control in a number of ways to build custom behaviors
into your applications .

No comments:

Post a Comment