<asp:GridView
ID="gvList"
runat="server"
AutoGenerateColumns="False"
EnableModelValidation="True"
HeaderStyle-HorizontalAlign="Center"
Width="100%"
RowStyle-Height="25px"
HeaderStyle-CssClass="ui-th-div-ie"
RowStyle-CssClass="TR_ROW1"
AlternatingRowStyle-CssClass="TR_ROW2"
HeaderStyle-ForeColor="#0073ea"
BorderWidth="1px"
CellPadding="2"
HorizontalAlign="Center"
OnPageIndexChanging="gvList_PageIndexChanging"
AllowPaging="true"
AllowSorting="true"
PagerStyle-HorizontalAlign="Right"
PageSize="1"
OnSorting="gvList_Sorting">
<Columns>
<asp:TemplateField HeaderStyle-Width="20%" HeaderText="<%$ Resources: CommonResources, lbl_InstoreHistLotNo.Text %>" SortExpression="LotNo">
<ItemTemplate>
<asp:Label ID="lbl_InstoreHistLotNo" runat="server" Text='<%#Eval("LotNo")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="10%" HeaderText="<%$ Resources: CommonResources, lbl_InstoreHistPartNo.Text %>" SortExpression="PartCode">
<ItemTemplate>
<asp:Label ID="lbl_InstoreHistPartNo" runat="server" Text='<%#Eval("PartCode")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="10%" HeaderText="<%$ Resources: CommonResources, lbl_InstoreHistPartName.Text %>" SortExpression="PartName">
<ItemTemplate>
<asp:Label ID="lbl_InstoreHistPartName" runat="server" Text='<%#Eval("PartName")%>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="10%" HeaderText="<%$ Resources: CommonResources, lbl_InstoreHistInQuality.Text %>" SortExpression="Quality">
<ItemStyle HorizontalAlign="Right" />
<ItemTemplate>
<asp:Label ID="lbl_InstoreHistInQuality" runat="server" Text='<%#Eval("Quality")%>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="10%" HeaderText="<%$ Resources: CommonResources, lbl_InstoreHistInUsercode.Text %>" SortExpression="UserCode">
<ItemTemplate>
<asp:Label ID="lbl_InstoreHistInUsercode" runat="server" Text='<%#Eval("UserCode")%>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="15%" HeaderText="<%$ Resources: CommonResources, lbl_InstoreHistInTime.Text %>" SortExpression="InStoreDate">
</asp:TemplateField>
</Columns>
<PagerStyle HorizontalAlign="Left" />
<PagerSettings Position="TopAndBottom" Mode="Numeric" />
</asp:GridView>
这只是一个简单的 gridview 数据绑定演示。但是,我的标题文本是从资源文件加载的,您可以自己设置,如字符串“aaa”、“bbb”、“ccc”
在后端,您的代码可能如下所示:
DataTable dt = SqlHelper.ExcuteDataSet("select * from InStoreHistory");
gvList.DataSource = dt;
gvList.DataBind();