I've been doing ASP.NET development for a little while now, and I've used both the GridView and the DataGrid controls before for various things, but I never could find a really good reason to use one or the other. I'd like to know:
我一直在做ASP。NET开发已经有一段时间了,我以前用过GridView和DataGrid控件来做各种事情,但是我从来没有找到一个真正好的理由来使用其中之一。我想知道:
What is the difference between these 2 ASP.NET controls? What are the advantages or disadvantages of both? Is one any faster? Newer? Easier to maintain?
这两个ASP之间的区别是什么?网络控制?两者的优缺点是什么?是一个快吗?更新的吗?更容易维护吗?
The intellisense summary for the controls doesn't seem to describe any difference between the two. They both can view, edit, and sort data and automatically generate columns at runtime.
这些控件的智能感知摘要似乎并没有描述两者之间的任何区别。它们都可以查看、编辑和排序数据,并在运行时自动生成列。
Edit: Visual Studio 2008 no longer lists DataGrid as an available control in the toolbox. It is still available (for legacy support I assume) if you type it in by hand though.
编辑:Visual Studio 2008不再将DataGrid列表为工具箱中的可用控件。不过,如果您手工输入的话,它仍然可用(我认为,用于遗留支持)。
8 个解决方案
#1
41
DataGrid was an ASP.NET 1.1 control, still supported. GridView arrived in 2.0, made certain tasks simpler added different databinding features:
数据网格是一个ASP。NET 1.1控件,仍然支持。GridView到达2.0,使某些任务更简单,添加了不同的数据库特性:
This link has a comparison of DataGrid and GridView features -
这个链接比较了DataGrid和GridView的特性
https://msdn.microsoft.com/en-us/library/05yye6k9(v=vs.100).aspx
https://msdn.microsoft.com/en-us/library/05yye6k9(v = vs.100). aspx
#2
7
The DataGrid was originally in .NET 1.0. The GridView was introduced (and replaced the DataGrid) in .NET 2.0. They provide nearly identical functionality.
DataGrid最初是在。net 1.0中。在。net 2.0中引入了GridView(并替换了DataGrid)。它们提供了几乎相同的功能。
#3
6
The GridView
control is the successor to the DataGrid
control. Like the DataGrid
control, the GridView
control was designed to display data in an HTML table. When bound to a data source, the DataGrid
and GridView
controls each display a row from a DataSource
as a row in an output table.
GridView控件是DataGrid控件的继承。与DataGrid控件一样,GridView控件被设计为在HTML表中显示数据。当绑定到数据源时,DataGrid和GridView控件都将从数据源中显示一行作为输出表中的一行。
Both the DataGrid
and GridView
controls are derived from the WebControl
class. Although it has a similar object model to that of the DataGrid
control, the GridView control also has a number of new features and advantages over the DataGrid
control, which include:
DataGrid和GridView控件都来自WebControl类。尽管与DataGrid控件的对象模型相似,GridView控件在DataGrid控件上也有许多新特性和优点,包括:
- 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.
- 具有PagerTemplate属性的自定义页导航用户界面(UI)。
Differences between the GridView
control and the DataGrid
control include:
GridView控件和DataGrid控件之间的差异包括:
- Different custom-paging support.
- 不同custom-paging支持。
- Different event models.
- 不同的事件模型。
Sorting, paging, and in-place editing of data requires additional coding when using the DataGrid
control. The GridView
control enables you to add sorting, paging, and editing capabilities without writing any code. Instead, you can automate these tasks, along with other common tasks such as data binding to a data source, by setting properties on the control.
在使用DataGrid控件时,数据的排序、分页和就地编辑需要额外的编码。GridView控件允许您添加排序、分页和编辑功能,而无需编写任何代码。相反,您可以通过设置控件上的属性,将这些任务以及其他常见任务(如数据绑定到数据源)自动化。
#4
5
If you're working in Visual Studio 2008 / .NET 3.5, you probably shouldn't use either. Use the ListView - it gives you the features of the GridView combined with the styling flexibility of a repeater.
如果你在Visual Studio 2008 /。net 3.5中工作,你可能也不应该使用它们。使用列表视图——它为您提供了GridView的特性以及中继器的样式灵活性。
#5
1
The key difference is in the ViewState management IIRC. The DataGrid requires ViewState turned on in order to have edit and sort capabilities.
关键的区别在于ViewState管理IIRC。DataGrid需要打开ViewState才能具有编辑和排序功能。
#6
1
One key difference security wise is that DataGrid uses BoundColumn which does not HtmlEncode the bound data. There is no property to turn HtmlEncoding on or off either, so you need to do it in code somehow.
一个关键的差异安全智能是DataGrid使用BoundColumn,它不使用HtmlEncode绑定数据。没有属性可以打开或关闭htmlencode,所以您需要以某种方式在代码中执行它。
GridView uses BoundField, which does HtmlEncode by default on the bound data and it has a HtmlEncode property if you need to turn it off.
GridView使用BoundField,它默认在绑定数据上执行HtmlEncode,如果需要关闭它,它有一个HtmlEncode属性。
#7
0
some basic diffrence between gridview and details view
gridview和details视图之间的一些基本差异
the GridView control also has a number of new features and advantages over the DataGrid control, which include:
与DataGrid控件相比,GridView控件还有一些新特性和优点,包括:
· 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.
·富设计时功能。·改进数据源绑定功能。·自动处理排序、分页、更新和删除。·附加列类型和设计时列操作。·具有PagerTemplate属性的自定义寻呼机用户界面(UI)。
Differences between the GridView control and the DataGrid control include: · Different custom-paging support. · Different event models.
GridView控件与DataGrid控件之间的差异包括:·不同的自定义分页支持。不同的事件模型。
#8
0
One of the differences is the HTML output. A datagrid will output TD's for the header and a gridview will output TH's. This can cause unintuitive changes in the display.
差异之一是HTML输出。一个datagrid将为标题输出TD,一个gridview将输出TH。这可能导致显示中出现不直观的变化。
#1
41
DataGrid was an ASP.NET 1.1 control, still supported. GridView arrived in 2.0, made certain tasks simpler added different databinding features:
数据网格是一个ASP。NET 1.1控件,仍然支持。GridView到达2.0,使某些任务更简单,添加了不同的数据库特性:
This link has a comparison of DataGrid and GridView features -
这个链接比较了DataGrid和GridView的特性
https://msdn.microsoft.com/en-us/library/05yye6k9(v=vs.100).aspx
https://msdn.microsoft.com/en-us/library/05yye6k9(v = vs.100). aspx
#2
7
The DataGrid was originally in .NET 1.0. The GridView was introduced (and replaced the DataGrid) in .NET 2.0. They provide nearly identical functionality.
DataGrid最初是在。net 1.0中。在。net 2.0中引入了GridView(并替换了DataGrid)。它们提供了几乎相同的功能。
#3
6
The GridView
control is the successor to the DataGrid
control. Like the DataGrid
control, the GridView
control was designed to display data in an HTML table. When bound to a data source, the DataGrid
and GridView
controls each display a row from a DataSource
as a row in an output table.
GridView控件是DataGrid控件的继承。与DataGrid控件一样,GridView控件被设计为在HTML表中显示数据。当绑定到数据源时,DataGrid和GridView控件都将从数据源中显示一行作为输出表中的一行。
Both the DataGrid
and GridView
controls are derived from the WebControl
class. Although it has a similar object model to that of the DataGrid
control, the GridView control also has a number of new features and advantages over the DataGrid
control, which include:
DataGrid和GridView控件都来自WebControl类。尽管与DataGrid控件的对象模型相似,GridView控件在DataGrid控件上也有许多新特性和优点,包括:
- 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.
- 具有PagerTemplate属性的自定义页导航用户界面(UI)。
Differences between the GridView
control and the DataGrid
control include:
GridView控件和DataGrid控件之间的差异包括:
- Different custom-paging support.
- 不同custom-paging支持。
- Different event models.
- 不同的事件模型。
Sorting, paging, and in-place editing of data requires additional coding when using the DataGrid
control. The GridView
control enables you to add sorting, paging, and editing capabilities without writing any code. Instead, you can automate these tasks, along with other common tasks such as data binding to a data source, by setting properties on the control.
在使用DataGrid控件时,数据的排序、分页和就地编辑需要额外的编码。GridView控件允许您添加排序、分页和编辑功能,而无需编写任何代码。相反,您可以通过设置控件上的属性,将这些任务以及其他常见任务(如数据绑定到数据源)自动化。
#4
5
If you're working in Visual Studio 2008 / .NET 3.5, you probably shouldn't use either. Use the ListView - it gives you the features of the GridView combined with the styling flexibility of a repeater.
如果你在Visual Studio 2008 /。net 3.5中工作,你可能也不应该使用它们。使用列表视图——它为您提供了GridView的特性以及中继器的样式灵活性。
#5
1
The key difference is in the ViewState management IIRC. The DataGrid requires ViewState turned on in order to have edit and sort capabilities.
关键的区别在于ViewState管理IIRC。DataGrid需要打开ViewState才能具有编辑和排序功能。
#6
1
One key difference security wise is that DataGrid uses BoundColumn which does not HtmlEncode the bound data. There is no property to turn HtmlEncoding on or off either, so you need to do it in code somehow.
一个关键的差异安全智能是DataGrid使用BoundColumn,它不使用HtmlEncode绑定数据。没有属性可以打开或关闭htmlencode,所以您需要以某种方式在代码中执行它。
GridView uses BoundField, which does HtmlEncode by default on the bound data and it has a HtmlEncode property if you need to turn it off.
GridView使用BoundField,它默认在绑定数据上执行HtmlEncode,如果需要关闭它,它有一个HtmlEncode属性。
#7
0
some basic diffrence between gridview and details view
gridview和details视图之间的一些基本差异
the GridView control also has a number of new features and advantages over the DataGrid control, which include:
与DataGrid控件相比,GridView控件还有一些新特性和优点,包括:
· 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.
·富设计时功能。·改进数据源绑定功能。·自动处理排序、分页、更新和删除。·附加列类型和设计时列操作。·具有PagerTemplate属性的自定义寻呼机用户界面(UI)。
Differences between the GridView control and the DataGrid control include: · Different custom-paging support. · Different event models.
GridView控件与DataGrid控件之间的差异包括:·不同的自定义分页支持。不同的事件模型。
#8
0
One of the differences is the HTML output. A datagrid will output TD's for the header and a gridview will output TH's. This can cause unintuitive changes in the display.
差异之一是HTML输出。一个datagrid将为标题输出TD,一个gridview将输出TH。这可能导致显示中出现不直观的变化。