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 控件也支持许多样式对象,可以让我们可以灵活的自订其显示外观,如下表所示:
