Click here to Skip to main content
15,909,039 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
ok this is not as simple as it sounds i have a gridview in which i am displaying data on labels now i want to show the total of columns in footer i tried to use rowdatabound event of gridview but i am not sure how to approach this one. my query is as follows:

SQL
string str = string.Format(@"select m.pcode,sum( m.salary) as SalaryConsumed, y.salary,sum(m.ta) as taConsumed,y.ta,sum(m.contigency) as contiused, y.contigency,sum(m.nrc) as nrcconsumed,y.nrc,sum(m.institcharges) as institgiven,y.institcharges,sum(m.others) as miscused,y.others, m.fyyear,y.yearlyalloc from monthly m
        inner join yearly y on m.pcode = y.pcode and m.fyyear = y.fyyear where m.pcode=('" + DropDownList1.SelectedItem.ToString() + "' ) AND m.fyyear=('" + DropDownList2.SelectedItem.ToString() + "')group by m.fyyear, m.pcode, y.salary, y.ta,y.contigency,y.nrc,y.institcharges,y.others,y.yearlyalloc", con);



in gridview rowdatabound event i know this is the code to be used but idont know what to add the label names that i have taken to show the data or the column names
C#
if (e.Row.RowType == DataControlRowType.DataRow)
       {
           mtot = columns or label? ;
       }
       if (e.Row.RowType == DataControlRowType.Footer)
       {
           Label mtot = (Label)e.Row.FindControl("expenditure");
           expenditure.Text = mtot.ToString();
       }


http://i45.tinypic.com/4g6exz.jpg[^]this is the image of my gridview
Posted
Updated 10-Apr-13 22:58pm
v3

like your requirement try this once

C#
private void GridView_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
  {
   DataTable dtGridview=(DataTable)Session["dtgridviewPreviousBindingdata"];
   if((e.Item.ItemType == ListItemType.Footer))
   {
    e.Item.HorizontalAlign=HorizontalAlign.Center;
    e.Item.CssClass="mainbgHead";
    e.Item.Cells[0].Text="";
    e.Item.Cells[1].Text ="Total ";
    e.Item.Cells[2].Text=dtGridview.Compute("sum(INTER)","").ToString();
    e.Item.Cells[3].Text=dtGridview.Compute("sum(Mutual)","").ToString();
    e.Item.Cells[4].Text=dtGridview.Compute("sum(Spouse)","").ToString();
   }
  }
 
Share this answer
 
 
Share this answer
 
Comments
a2ulthakur 11-Apr-13 5:05am    
thanks abhinav but its not in there i have seen all the resources before
C#
if (e.Row.RowType == DataControlRowType.DataRow)
        {
            
            mtot1 = Convert.ToDouble(((DataRowView)e.Row.DataItem)["Salaryconsumed"].ToString());
            mtot2 = Convert.ToDouble(((DataRowView)e.Row.DataItem)["taconsumed"].ToString());
            mtot3 = Convert.ToDouble(((DataRowView)e.Row.DataItem)["contiused"].ToString());
            mtot4 = Convert.ToDouble(((DataRowView)e.Row.DataItem)["institgiven"].ToString());
            mtot5 = Convert.ToDouble(((DataRowView)e.Row.DataItem)["nrcconsumed"].ToString());
            mtot6 = Convert.ToDouble(((DataRowView)e.Row.DataItem)["miscused"].ToString());
            mtot7 = mtot1 + mtot2 + mtot3 + mtot4 + mtot5 + mtot6;
        }

        if (e.Row.RowType == DataControlRowType.Footer)
        {
            Label yalloc = (Label)e.Row.FindControl("ex");
            yalloc.Text = mtot7.ToString();
        }<pre lang="c#"><pre lang="c#">
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900