【发布时间】:2011-06-10 01:06:47
【问题描述】:
我有一个 2 列的网格视图。我想学习后面的编码并且不想在 aspx 文件中这样做。 如何动态设置列的标题文本?我在什么时候这样做?在适配器用数据填充网格视图之后? 现在,我有标题文本,但它与 last_name 的数据字段名称完全相同,我想在标题字段中查看姓氏。 我试过了
GridView1.Columns[0].HeaderText = "Last Name";
但是无论我试图把它放在哪里,编译器都会抱怨索引超出范围。
谢谢。
gridview的aspx代码:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px"
Width="728px" CellPadding="4" ForeColor="Black" GridLines="Vertical" OnPageIndexChanging="GridView1_PageIndexChanging"
OnSorting="GridView1_Sorting" PageSize="14" OnRowDataBound="GridView1_RowDataBound">
<AlternatingRowStyle BackColor="White" />
<FooterStyle BackColor="#CCCC99" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<RowStyle BackColor="#F7F7DE" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#FBFBF2" />
<SortedAscendingHeaderStyle BackColor="#848384" />
<SortedDescendingCellStyle BackColor="#EAEAD3" />
<SortedDescendingHeaderStyle BackColor="#575357" />
<PagerSettings Mode="NumericFirstLast" FirstPageText="First" LastPageText="Last"
PageButtonCount="5" Position="Bottom" />
</asp:GridView>
【问题讨论】: