Go to DotNetFunda.com
 Online : 1371 |  Welcome, Guest!   Login
 
Home > Articles > ADO.NET > Diff Between DataGrid and GridView

Submit Article | Articles Home | Search Articles |

Diff Between DataGrid and GridView

red flag  Posted on: 9/17/2008 11:20:35 PM by Majith | Views: 7631 | Category: ADO.NET | Level: Intermediate


Im going to expail the various difference between GridView and the DataGrid controls and their different logics.



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 .

Conclusion

The above article describes the simple diff logics between GridView and DataGrid Controls.

Cheers Coding!



 


If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Found interesting? Add this to:

| More



Please Sign In to vote for this post.

 
Latest post(s) from Majith

Latest Articles

About Majith Basha

Experience:0 year(s)
Home page:
Member since:Friday, July 18, 2008
Level:Starter
Status: [Member]
Biography:

Submit Article

About Us | The Team | Advertise | Contact Us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you found plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 9/3/2010 4:11:12 AM