473,414 Members | 1,692 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Problem in nested gridview

375 256MB
Hi,

I have a gridview problem while binding more than two gridviews.

I am giving a sample scenario of what I have done so far

I have two tables

First table: Department , having columns DeptId and DeptName

10 Accounts
20 Software

Second Table: Emp having columns EmpId, EmpName,Salary,
DeptID.

101 aaa 100 10
101 aaa 200 10
101 aaa 300 10
202 bb 101 20
202 bb 102 20
102 cc 100 10
201 dd 103 20


I am supposed to show first all the employees ordered by their deptname.

Also I am supposed to show the sum of each employees salary and sum of the entire department's salary

So the above values should appear as below

101 aaa 100 10
101 aaa 200 10
101 aaa 300 10
sum of emp 101 is 600
102 cc 100 10
sum of emp 102 is 100
SUM OF DEPT 10 IS 700


202 bb 101 20
202 bb 102 20
sum of emp 202 is 203
201 dd 103 20
sum of emp 202 is 103
SUM OF DEPT 20 IS 306


I am able to fetch sum of dept salary but not of employees

I have tried as below

My Design Page
.


Expand|Select|Wrap|Line Numbers
  1.  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowDataBound="GridView1_RowDataBound">
  2.                 <Columns>
  3.                 <asp:BoundField DataField="DeptID" />
  4.                     <asp:TemplateField>
  5.                         <ItemTemplate>
  6.  
  7.                                 <asp:GridView ID="GridView2"  AutoGenerateColumns="false" runat="server">
  8.                                     <Columns>
  9.                                         <asp:BoundField DataField="EmpId" />
  10.                                         <asp:BoundField DataField="EmpName" />
  11.                                         <asp:BoundField DataField="Salary" />
  12.                                     </Columns>
  13.                                 </asp:GridView>
  14.                                 <asp:GridView ID="GridView3"  AutoGenerateColumns="false" runat="server">
  15.                                     <Columns>
  16.                                         <asp:BoundField DataField="SumSalary" />
  17.                                     </Columns>
  18.                                 </asp:GridView>
  19.  
  20.                         </ItemTemplate>
  21.                     </asp:TemplateField>
  22.                 </Columns>
  23.             </asp:GridView>
My Codebehind page is as below


Expand|Select|Wrap|Line Numbers
  1.  SqlConnection MyCon=new SqlConnection("server=ABC-415D0247602\\SQLEXPRESS; database=Employee ;integrated security=true;connection timeout=600");
  2.  
  3.     protected void Page_Load(object sender, EventArgs e)
  4.     {
  5.         MyCon.Open();
  6.         SqlDataAdapter MyDa = new SqlDataAdapter("select * from department", MyCon);
  7.         DataSet MyDs = new DataSet();
  8.         MyDa.Fill(MyDs);
  9.         DataTable MyDt = new DataTable();
  10.         GridView1.DataSource = MyDs.Tables[0];
  11.         GridView1.DataBind();
  12.  
  13.  
  14.     }
  15.     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  16.     {
  17.         if (e.Row.RowType == DataControlRowType.DataRow)
  18.         {
  19.             string j = e.Row.Cells[0].Text;
  20.  
  21.             GridView GridView2 = (GridView)e.Row.FindControl("GridView2");
  22.             SqlDataAdapter MyDa1 = new SqlDataAdapter("select * from Emp where deptid =" +Convert.ToInt16(j), MyCon);
  23.             DataSet MyDs1 = new DataSet();
  24.             MyDa1.Fill(MyDs1);
  25.             DataTable MyDt1 = new DataTable();
  26.             GridView2.DataSource = MyDs1.Tables[0];
  27.             GridView2.DataBind();
  28.  
  29.             GridView GridView3 = (GridView)e.Row.FindControl("GridView3");
  30.             SqlDataAdapter MyDa2 = new SqlDataAdapter("select sum(salary) as SumSalary from Emp where deptid =" + Convert.ToInt16(j), MyCon);
  31.             DataSet MyDs2 = new DataSet();
  32.             MyDa2.Fill(MyDs2);
  33.             DataTable MyDt2 = new DataTable();
  34.             GridView3.DataSource = MyDs2.Tables[0];
  35.             GridView3.DataBind();
  36.         }
  37.     }
I do not know where to place the sum of the employee's salary


Thanks in advance



Regards

cmrhema
Dec 16 '09 #1
0 1858

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: hammad.awan_nospam | last post by:
Hello, I am using ASP.NET 2.0. What I have done is nested a gridview inside another column of a gridview using a template data field column declaritively in my web form. Inside this child...
2
by: bigbrorpi | last post by:
Hi I have a FormView that contains a GridView. The GridView is populated from an ObjectDataSource. Two of the columns in the GridView are not bound, and the values used in Update mode come from...
0
by: manuel.ricca | last post by:
Hello, I'm trying to create a table with 2 nested gridviews and then a DetailsView on the right. The DetailsView should show the details of the item selected in the 2nd (nested) GridView: My...
0
by: Mudassar | last post by:
I am facing a problem while accessing the gridview in nested gridview structure. Some time i found child gridview control but when i bind data to child gridview it doesnt
3
by: Jeff | last post by:
Hey asp.net 2.0 In the source I posted below, there is a GridView (look at the bottom of the script): <asp:GridView ID="gvwOnline" runat="server"> </asp:GridView> I'm trying to assign a...
0
by: mutt1170 | last post by:
I have a checkbox list nested inside a gridview. The gridview pulls its data from an objectdatasource and lists countries. The nested checkbox list is databound to another object datasource and...
2
by: GISmatters | last post by:
I have unbound checkboxes in a nested gridview to allow multi-selection of "child" rows. For context, the parent gridview rows are for large "reports", the child rows are for various specific files...
1
by: webby98 | last post by:
I have an issues using LINQ and nested gridview. Let me explain, Gridview A are the for grouping. And Gridview B are place in between Gridview A to display list data relate to Gridview A...
2
by: ASF | last post by:
Hey all, I have a gridview which pulls from a BLL which pulls from a DAL (an .XSD file). Each row on that gridview has a nested repeater which pulls from another table. The code which populates...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.