How can i display employee details in gridview along with total salary of all employees. [Resolved]

Posted by Udaysimha under ASP.NET on 1/9/2012 | Points: 10 | Views : 3851 | Status : [Member] | Replies : 4
Hi All,

I have a requirement that is i need to display employee details in gridview as well as i need to calculate total salary of all employees and
i need to display that total amount in bottom of gridview.

Please anybody let me give some idea to achieve this, any help would be appreciated.

Thanks in advance

uday


Responses

Posted by: Prabhakar on: 1/9/2012 [Member] [MVP] Starter | Points: 50

Up
0
Down

Resolved
Hi Uday,


go with this article . . it's help us u . .

http://csharpdotnetfreak.blogspot.com/2009/07/display-total-in-gridview-footer.html

Best Regard's
Prabhakar

Udaysimha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Self-innovator on: 1/9/2012 [Member] Bronze | Points: 25

Up
0
Down

Design.aspx
  <FooterTemplate>

<%# gettotal() %>

</FooterTemplate>

.cs
 public string gettotal()

{
SqlConnection cnn = new SqlConnection(Conn);
cnn.Open();
SqlCommand cmd = new SqlCommand("SELECT SUM(EmpSalary) FROM empp", cnn);
int totSal = Convert.ToInt32(cmd.ExecuteScalar());
string Sal = totSal.ToString();
return Sal;
}


Join Hands Change lives
Thanks & Regards
Straight Edge Society

Udaysimha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Blessyjees on: 1/9/2012 [Member] Bronze | Points: 25

Up
0
Down
hi,

You can read all employee details from db as data table and set this data table as the source of data grid. and you can find the total salary using linq and set this value to grid.

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Udaysimha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 1/9/2012 [Member] Silver | Points: 25

Up
0
Down
Another Way......................................
///call your procedure it should return 2 tables
//table 1 will return emp details
//table 2 will return sum (salary)
Now.....
GridView gv = new GridView();
gv.DataSource = ds.Tables[0];
gv.DataBind();
gv.FooterRow.Visible = true;
gv.FooterRow.Cells[0].Text = "500";////to test i have put static value here you can use ds.Tables[1].rows[0]["sumsalary"].ToString();
this.form1.Controls.Add(gv);

Thanks,
Sanjay

Udaysimha, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response