不敢相信我不得不问这个 - 你会认为这样一个基本的特性很容易实现,但是我无法为Gridview创建页脚。我已经检查了各种教程和其他问题,如here,和here和here,但我仍然遇到困难。为什么Gridview页脚添加一个额外的列?
问题在于正确显示页脚(即不添加多余的空列)。从我收集的内容来看,您需要将FooterTemplate放在TemplateField标签内,否则它将无法工作 - 至少它不会为我编译。如果我在BoundFields列之后插入它,那么它会添加一个不需要的额外列。
<asp:GridView ID="gridview1" runat="server" AutoGenerateColumns="false" AllowSorting="true"
CellPadding="3" HorizontalAlign="Center" GridLines="both" CssClass="dataTable1"
OnRowDataBound="Colour_Columns" Caption="PARTIAL COMPARE" ShowFooter="true">
<HeaderStyle BackColor="Black" ForeColor="AntiqueWhite" Height="30" CssClass="header" />
<FooterStyle BackColor="Black" ForeColor="AntiqueWhite" Height="30" CssClass="footer" />
<Columns>
<asp:BoundField DataField="FOLDER" HeaderText="Location" />
<asp:BoundField DataField="FILE" HeaderText="File" />
<asp:BoundField DataField="CHECKSUM" HeaderText="Checksum" Visible="false" />
<asp:BoundField DataField="STATUS" HeaderText="Status" />
<asp:BoundField DataField="DATE" HeaderText="Date" Visible="false" />
<asp:TemplateField>
<FooterTemplate>
<asp:Button ID="UpdateButton" runat="server" Text="UPDATE" CssClass="updateButton" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
同样,如果我把它绑定列前将其添加在左侧有一个额外的列。如果我尝试将所有BoundFields放在TemplateField下,它将不会编译。
如何在不创建额外列的情况下将页脚添加到gridview?另外,当我们处理它时,我怎样才能将它的colspan设置为1? (这只是将不得不在它的一个更新按钮,所以没有必要在页脚三列)。
颜色方案方法:
protected void Colour_Columns(Object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[3].Text == "Match")
e.Row.BackColor = Color.Lime;
if (e.Row.Cells[3].Text == "Mismatch")
e.Row.BackColor = Color.Gold;
if (e.Row.Cells[3].Text == "New File")
e.Row.BackColor = Color.PeachPuff;
}
}
这种方法似乎并没有认识到的ItemTemplate值...
您已经添加了一个模板字段,这就是为什么它显示一个额外的空的列与页脚中的按钮。 – 2013-03-27 14:01:51
@CodeRider是的,但如果我不添加TemplateField它不会允许FooterTemplate ... – user1985189 2013-03-27 14:13:09
正是你想要的?您在运行时隐藏了几列。如果你将隐藏列,那么页脚会隐藏自己。请详细说明,你想要什么。 – 2013-03-27 14:17:27