Hi,
I want to show a column of database in footer of gridview
the column name is Total
this is my code but it shows 0
<asp:GridView ID="gvodinfo" runat="server" AutoGenerateColumns="False" onrowdatabound="gvodinfo_RowDataBound"
showfooter="true" >
<Columns>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:Label ID="lblpdid" runat="server" Text='<%#Eval("pd_id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:Label ID="lblpdname" runat="server" Text='<%#Eval("pd_name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ا">
<ItemTemplate>
<asp:Label ID="lblprice" runat="server" Text='<%#Eval("odl_price") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:Label ID="lblq" runat="server" Text='<%#Eval("odl_quantity") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblTotal" runat="server" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
protected void gvodinfo_RowDataBound(object sender, GridViewRowEventArgs e)
{
int Totalmarks = 0;
if (e.Row.RowType == DataControlRowType.DataRow)
{
Totalmarks = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Total"));//Total is database column name
}
if (e.Row.RowType == DataControlRowType.Footer)
{
Label lblTotal = (Label)e.Row.FindControl("lblTotal");
lblTotal.Text = "Total :" + Totalmarks;
}
}
thanks a lot