Calculations and two gridviews

Asked By Rosie Buchanan
09-Feb-10 02:58 PM
Earn up to 0 extra points for answering this tough question.
I'm back...

This is what I'm trying to achieve:

         Month

Current Month

 Month

     Total

4/3/2009

$00.00

Jan

$0.00

4/17/2009

$00.00

Feb

$0.00

5/1/2009

$00.00

Mar

$0.00

5/15/2009

$00.00

Apr

$0.00

5/29/2009

$00.00

May

$0.00

6/12/2009

$0.00

Jun

$0.00

6/26/2009

$0.00

July

$0.00

7/10/2009

$0.00

Aug

$0.00

Sept

$0.00

Oct

$0.00

Nov

$0.00

Dec

$0.00

I want to be able to add
50.00 next to 4/2/2009 Under the current month column
and
20.00 next to 4/17/2009

I would like the total of 70.00 to go under the total column next to the April section.

I have the above set up but I had to use two gridviews to get the month's listed.  Here are the gridview's:

 

 

<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="False" Width="103px" Font-Names="Calibri">

 

 

<Columns>

 

 

 

 

<asp:BoundField DataField="Dates" HeaderText="PPE Date" SortExpression="Dates" />

 

 

 

 

<asp:TemplateField HeaderText="Amount">

 

 

 <

 

ItemTemplate>

 

 <

 

asp:TextBox ID="TextBox1" runat="server" Width="99px"></asp:TextBox
 </
 
ItemTemplate>

 

 

 </

 

asp:TemplateField>

 

 

 </

 

Columns>

 

 

 

 

</asp:GridView>

 

 

 

 

</td>

 

 

 

 

<td style="width: 100px">

 

 

 

 

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource2">

 

 

 

 

<Columns>

 

 

 <

 

asp:BoundField DataField="MonthVal" HeaderText="MonthVal" ReadOnly="True" SortExpression="MonthVal" Visible="False" />

 

 

 

 

<asp:BoundField DataField="MonthName" ReadOnly="True" SortExpression="MonthName" />

 

 

 

 

<asp:TemplateField HeaderText="Total">

 

 

 <

 

ItemTemplate>

 

 

 <

 

asp:TextBox ID="TextBox6" runat="server" Width="69px"></asp:TextBox>

 

 

 </

 

ItemTemplate>

 

 

 </

 

asp:TemplateField>

 

 

 

 

</Columns>

 

 

 

 

</asp:GridView>

 

 

 Is this possible to be able to calculate in one gridview and display the answer in the other gridview or should I use a label?

 

 

 

  re: Calculations and two gridviews

Pranay Singh replied to Rosie Buchanan
09-Feb-10 04:01 PM
You cannot do calculations in Gridview, its just for display purpose, you can either do it at database level by a stored proc to show the sum of amounts selected by months or you can capture the cell values of the gridview( based on month)  convert them to decimal  add them,  store them in  dataset object and feed it to the other gridview.  1st approach is easier, but it would require an extra call to database, 2nd approach is little complicated and need some coding.
I hope this gives you some idea.

  re: re: Calculations and two gridviews

Rosie Buchanan replied to Pranay Singh
09-Feb-10 06:29 PM
Thanks I see this is going to be tough to handle so I would want to do it another way.  Instead of what I proposed how would I add capture the value of a gridview cell(s) and add them together and place the total in a label or a footer.  I would do this with only one gridview.

  re: re: re: Calculations and two gridviews

Pranay Singh replied to Rosie Buchanan
10-Feb-10 08:43 AM
No, its not tough to handle if you do it at database level, all you need is stored proc.   and  if you have to show total just for the current month yeh you can use label but display is another thing 1st you need to decide how to capture these values...label or gridview wont make your work any different...but yeh Label is preferred option over gridview if you have just a grand total to display.
all the best
Create New Account