hi i tried for three pages but am getting total sum in grid footer..
but in other two pages am not getting sum..
error "Object reference is not set to an instance of an object"
can any one help me..
here is my code..
protected void grdCurrencyProfit_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
decimal rowTotal1 = Convert.ToDecimal
(DataBinder.Eval(e.Row.DataItem, "tTotalAmount"));
grdTotal1 = grdTotal1 + rowTotal1;
decimal rowTotal2 = Convert.ToDecimal
(DataBinder.Eval(e.Row.DataItem, "tSales"));
grdTotal2 = grdTotal2 + rowTotal2;
decimal rowTotal3 = Convert.ToDecimal
(DataBinder.Eval(e.Row.DataItem, "tProfitAmount"));
grdTotal3 = grdTotal3 + rowTotal3;
}
if (e.Row.RowType == DataControlRowType.Footer)
{
Label lbl1 = (Label)e.Row.FindControl("lblPurchase");
Label lbl2 = (Label)e.Row.FindControl("lblSale");
Label lbl3 = (Label)e.Row.FindControl("lblProfit");
lbl1.Text = grdTotal1.ToString("c");
lbl2.Text = grdTotal2.ToString("c");
lbl3.Text = grdTotal3.ToString("c");
}
}
before page load.
public partial class Ticketing : System.Web.UI.Page
{
decimal grdTotal1 = 0;
decimal grdTotal2 = 0;
decimal grdTotal3 = 0;
and in grid html code
<asp:GridView ID="grdCurrencyProfit" runat="server" AutoGenerateColumns="false" Width="333px"
AllowPaging="True" AllowSorting="True" PageSize="5" OnPageIndexChanging="grdCurrencyProfit_PageIndexChanging"
ShowFooter="true" BackColor="#ffffff" BorderColor="AliceBlue" BorderStyle="None"
BorderWidth="1px" CellPadding="3" CellSpacing="2" FooterStyle-BackColor="#da821e"
FooterStyle-ForeColor="#ffffff" RowStyle-BackColor="#003366" RowStyle-ForeColor="#ffffff"
AlternatingRowStyle-BackColor="#da821e" OnRowDataBound="grdCurrencyProfit_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="Subject" FooterText="TOTAL">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "tSubject")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total Amount">
<ItemTemplate>
<asp:Label ID="lblPurchase" runat="server" Text='<%# "Rs"+Eval("tTotalAmount").ToString()%>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Sales Amount">
<ItemTemplate>
<asp:Label ID="lblSale" runat="server" Text='<%# "Rs"+Eval("tSales").ToString()%>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Profit">
<ItemTemplate>
<asp:Label ID="lblProfit" runat="server" Text='<%# "Rs"+Eval("tProfitAmount").ToString()%>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "tDateofJourney")%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<HeaderStyle BackColor="#da821e" Font-Bold="True" ForeColor="White" />
</asp:GridView>
am not able to solve this small issue..can any one suggest me??
thanks