I added ShowFooter="True" for my gridview and added a blank template for footer
<asp:GridView ID="GridView3" runat="server"
DataKeyNames="photo_ID"
DataSourceID="ObjectDataSource3" Style="position: static"
CssSelectorClass="PrettyGridView"
ShowFooter="True" OnRowCommand="GridView3_RowCommand"
>
<Columns>
........
...
<asp:TemplateField HeaderText="% Return" >
<FooterTemplate>
</FooterTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle CssClass="CELL_footer" />
</asp:GridView>
And in the RowDataBound Event, I can dynamically generate the content of the footer:
protected void GridView3_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Footer) //draw table footer
{
double _total_return = Convert.ToDouble(Total_label.Text);
String formated_total = string.Format("{0:P2}", _total_return);
e.Row.Cells[7].Text = formated_total ;
}
}
This method only for add a new row at the bottom of Gridview.
Anthoer trickey method required If you want to add subheaders in the Gridview with CSS friendly adpater. Basically you need reformat the content of the first Cell text in the row. But I am not sure it is a good solution.