473,782 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem in nested gridview

375 Contributor
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 1885

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

Similar topics

0
2209
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 gridview I have set an ItemStyle property of width 20% for the first templated field which contains a hyperlink control, and an ItemStyle of width 80% for the second templated field which contains a label. Both of these controls are databound to...
2
2383
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 dropdowns (inside of ItemTemplates). In my ObjectDataSource, I have Parameters for the bound fields, and ControlParameters for the DDLs. I cannot seem to access the DDLs since they are so nested. I've tried:
0
2805
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 "master" table is like this: A1
0
1227
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
4605
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 datasource to this GridView in runtime. But I cannot
0
3518
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 lists the regions for each country. The checkboxlist has autopostback set to true and I want to perform an action based on whether or not each checkbox is selected. I am having trouble retrieving the nested checkboxlist to access the selected...
2
2830
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 comprising each report. I want the user to be able to select an arbitrary collection of report files and have them emailed by clicking an "Email selected files" button. Everything displays properly, including the checkboxes for each child row (each...
1
1772
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 grouping. Both GridView will need to be populate dynamically on runtime via stored procedure and using LINQ. 1st SPROC are to get the grouping data for Gridview A 2nd SPROC are to get record for Gridview B base on a
2
2607
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 each nested repeater is shown below (it's in the gridview's RowDataBound event). My question is this: what can I do to speed up this process? Currently EVERY time a new gridview row is generated the code reaches out to the database, grabs the...
0
9639
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10146
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10080
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8967
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6733
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5509
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4043
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2874
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.