Can't believe I have to ask this - you'd think such a basic feature would be straightforward to implement, but I'm having trouble creating a footer for a Gridview. I've checked out various tutorials and other questions, such as here, and here and here, but am still encountering difficulties.
The problem is in displaying the footer properly (i.e. without adding an extra empty column). From what I gather, you need to put the FooterTemplate inside a TemplateField tag or it won't work - at least it wouldn't compile for me. If I insert this after the BoundFields columns then it adds an extra column which is not desirable.
<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>
Similarly, if I put it before the BoundFields it adds an extra column on the left. If I try to put all the BoundFields under the TemplateField it won't compile.
How do I add the footer to the gridview without creating an extra column? Also, while we're at it, how can I set its colspan to 1? (It's only going to have the one Update button in it, so no need for three columns in the footer.)
Colour-Scheme method:
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;
}
}
This method does not seem to recognize ItemTemplate values...