列
可以在 GridView 中使用七种不同的列类型。
<asp:GridView ID="GridView1" runat="server">
<Columns>
...
</Columns>
</asp:GridView>
绑定列:
<asp:BoundField DataField="EmployeeID" HeaderText="Employee ID" />
ButtonField 字段:
<asp:ButtonField ButtonType="Button" HeaderText="Select Employee" Text="Select"/>
CheckBoxField 字段:
<asp:CheckBoxField DataField="IsActive" HeaderText="Is Active" />
CommandField 字段:
<asp:CommandField ShowDeleteButton="true"
ShowEditButton="true"
ShowInsertButton="true"
ShowSelectButton="true" />
HyperLinkField 字段:
<asp:HyperLinkField HeaderText="Employee Profile"
DataNavigateUrlFields="EmployeeID"
DataNavigateUrlFormatString="EmployeeProfile.aspx?EmployeeID={0}" />
ImageField 字段:
<asp:ImageField HeaderText="Photo"
DataImageUrlField="EmployeeID"
DataImageUrlFormatString="/images/{0}" />
模板列:
<asp:TemplateField>
<HeaderTemplate>
Name
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblEmployeeName"
runat="server"
Text='<&# Eval("EmployeeName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>