DataGrid Web 控件是三个Web 数据显示控件之中功能最强的。我们在撰写动态网页的时候,常需要将数据以不同的风格呈现出来;DataGrid Web 控件和上述介绍的Repeater Web 控件及DataList Web 控件都可以办到。但如果所要呈现的数据量非常庞大,而需要将这些数据分页展示的话,那就要靠DataGrid Web 控件了;DataGrid Web 控件除了支持分页的功能外,也可以让使用者编修数据。其使用语法为:
<ASP:DataGrid Id="被程序代码所控制的名称" Runat="Server" DataSource='<%#数据系结叙述%>' AllowPaging="True | False" AllowSorting="True | False" AutoGenerateColumns="True | False" BackImageUrl="url" CellPadding="像素" CellSpacing="像素" DataKeyField="主键字段" GridLines="None | Horizontal | Vertical | Both" HorizontalAlign="Center | Justify | Left | NotSet | Right" PagedDataSource PageSize="ItemCount" ShowFooter="True | False" ShowHeader="True | False" VirtualItemCount="ItemCount" AlternatingItemStyle-Property="value" EditItemStyle-Property="value" FooterStyle-Property="value" HeaderStyle-Property="value" ItemStyle-Property="value" PagerStyle-Property="value" SelectedItemStyle-Property="value" OnCancelCommand="事件程序" OnDeleteCommand="事件程序" OnEditCommand="事件程序" OnItemCommand="事件程序" OnItemCreated="事件程序" OnPageIndexChanged="事件程序" OnSortCommand="事件程序" OnUpdateCommand="事件程序" />
或
<ASP:DataGrid Id="被程序代码所控制的名称" Runat="Server" AutoGenerateColumns="False" DataSource='<%# DataBindingExpression %>' 其它属性设定... <Property Name="Columns"> <ASP:BoundColumn/> <ASP:EditCommandColumn/> <ASP:HyperlinkColumn/> <ASP:TemplateColumn> 样版设定... </ASP:TemplateColumn> </Property> </ASP:DataGrid>
DataGrid Web 控件常用的属性如下表所示:
DataGrid Web 控件所支持的样版如下表所示:
DataGrid Web 控件也支持许多样式对象,可以让我们可以灵活的自订其显示外观,如下表所示:
|