Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > add a new row with totals - gridview

Reply
Thread Tools

add a new row with totals - gridview

 
 
John
Guest
Posts: n/a
 
      06-09-2006
have a gridview where I need to add totals for each grouped data,

example
my grid looks like this
Sales 2006:
BMW 100
Lexus 75
Mercedes 70
Total Sales: 245

Sales 2005:
BMW 90
Lexus 40
Mercedes 10
Total Sales: 140

I have the formatting done for all but the Total Sales row, how can I add
that to my gridview?





 
Reply With Quote
 
 
 
 
Bruno Alexandre
Guest
Posts: n/a
 
      06-10-2006
it's easy

in one of the templates add the code

<footerItem>
<asp:label runat="server" id="lblTotal" text='<%= intTotal %>' />
</footerItem>

add
Dim intTotal as Integer = 0
at the begining of your script (outside Page_Load)

you probably use a function to calculate the totals of the year, just add
this line toyour code

intTotal += yourBrandTotal

If you are getting the total directly from the Database in a column named,
for example, tTotal you problable have the code like this in your template
item

<asp:label runat="server" id="lblBrandTotal" Text='<%# Eval("tTotal") %>' />


just it for this:
<asp:label runat="server" id="lblBrandTotal" Text='<%# addTotal(
Eval("tTotal") ) %>' />

and ad a function called addTotal like:

Function addTotal( myValue as integer ) as integer
intTotal += myValue
return myValue
End function

and that's it

--

Bruno Alexandre
(a Portuguese in Københanv, Danmark)


"John" <(E-Mail Removed)> escreveu na mensagem
news:(E-Mail Removed)...
> have a gridview where I need to add totals for each grouped data,
>
> example
> my grid looks like this
> Sales 2006:
> BMW 100
> Lexus 75
> Mercedes 70
> Total Sales: 245
>
> Sales 2005:
> BMW 90
> Lexus 40
> Mercedes 10
> Total Sales: 140
>
> I have the formatting done for all but the Total Sales row, how can I add
> that to my gridview?
>
>
>
>
>



 
Reply With Quote
 
 
 
 
John
Guest
Posts: n/a
 
      06-11-2006
I don't want the total in the footer. I want the total for each year like
this:
Sales 2006:
BMW 100
Lexus 75
Mercedes 70
Total Sales: 245
Sales 2005:
BMW 90
Lexus 40
Mercedes 10
Total Sales: 140

I will be adding a total in the footer of all the totals, but for this I
want the totals as above.




"Bruno Alexandre" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> it's easy
>
> in one of the templates add the code
>
> <footerItem>
> <asp:label runat="server" id="lblTotal" text='<%= intTotal %>' />
> </footerItem>
>
> add
> Dim intTotal as Integer = 0
> at the begining of your script (outside Page_Load)
>
> you probably use a function to calculate the totals of the year, just add
> this line toyour code
>
> intTotal += yourBrandTotal
>
> If you are getting the total directly from the Database in a column named,
> for example, tTotal you problable have the code like this in your template
> item
>
> <asp:label runat="server" id="lblBrandTotal" Text='<%# Eval("tTotal") %>'
> />
>
>
> just it for this:
> <asp:label runat="server" id="lblBrandTotal" Text='<%# addTotal(
> Eval("tTotal") ) %>' />
>
> and ad a function called addTotal like:
>
> Function addTotal( myValue as integer ) as integer
> intTotal += myValue
> return myValue
> End function
>
> and that's it
>
> --
>
> Bruno Alexandre
> (a Portuguese in Københanv, Danmark)
>
>
> "John" <(E-Mail Removed)> escreveu na mensagem
> news:(E-Mail Removed)...
>> have a gridview where I need to add totals for each grouped data,
>>
>> example
>> my grid looks like this
>> Sales 2006:
>> BMW 100
>> Lexus 75
>> Mercedes 70
>> Total Sales: 245
>>
>> Sales 2005:
>> BMW 90
>> Lexus 40
>> Mercedes 10
>> Total Sales: 140
>>
>> I have the formatting done for all but the Total Sales row, how can I add
>> that to my gridview?
>>
>>
>>
>>
>>

>
>



 
Reply With Quote
 
Bruno Alexandre
Guest
Posts: n/a
 
      06-11-2006
ok then,

using the gridview_rowcreate you can add a row with the totals everytime
you change the year

or

do that in the SQL Statment using GROUP BY Clause

--

Bruno Alexandre
(a Portuguese in Københanv, Danmark)


"John" <(E-Mail Removed)> escreveu na mensagem
news:(E-Mail Removed)...
>I don't want the total in the footer. I want the total for each year like
>this:
> Sales 2006:
> BMW 100
> Lexus 75
> Mercedes 70
> Total Sales: 245
> Sales 2005:
> BMW 90
> Lexus 40
> Mercedes 10
> Total Sales: 140
>
> I will be adding a total in the footer of all the totals, but for this I
> want the totals as above.
>
>
>
>
> "Bruno Alexandre" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> it's easy
>>
>> in one of the templates add the code
>>
>> <footerItem>
>> <asp:label runat="server" id="lblTotal" text='<%= intTotal %>' />
>> </footerItem>
>>
>> add
>> Dim intTotal as Integer = 0
>> at the begining of your script (outside Page_Load)
>>
>> you probably use a function to calculate the totals of the year, just add
>> this line toyour code
>>
>> intTotal += yourBrandTotal
>>
>> If you are getting the total directly from the Database in a column
>> named, for example, tTotal you problable have the code like this in your
>> template item
>>
>> <asp:label runat="server" id="lblBrandTotal" Text='<%# Eval("tTotal") %>'
>> />
>>
>>
>> just it for this:
>> <asp:label runat="server" id="lblBrandTotal" Text='<%# addTotal(
>> Eval("tTotal") ) %>' />
>>
>> and ad a function called addTotal like:
>>
>> Function addTotal( myValue as integer ) as integer
>> intTotal += myValue
>> return myValue
>> End function
>>
>> and that's it
>>
>> --
>>
>> Bruno Alexandre
>> (a Portuguese in Københanv, Danmark)
>>
>>
>> "John" <(E-Mail Removed)> escreveu na mensagem
>> news:(E-Mail Removed)...
>>> have a gridview where I need to add totals for each grouped data,
>>>
>>> example
>>> my grid looks like this
>>> Sales 2006:
>>> BMW 100
>>> Lexus 75
>>> Mercedes 70
>>> Total Sales: 245
>>>
>>> Sales 2005:
>>> BMW 90
>>> Lexus 40
>>> Mercedes 10
>>> Total Sales: 140
>>>
>>> I have the formatting done for all but the Total Sales row, how can I
>>> add
>>> that to my gridview?
>>>
>>>
>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
John
Guest
Posts: n/a
 
      06-13-2006
do u have a code snippet of something like this? I can't use the SQL (stored
procedure) due to its used by other apps that don't want the data grouped or
rolled up as I need to do on my web for
"Bruno Alexandre" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> ok then,
>
> using the gridview_rowcreate you can add a row with the totals everytime
> you change the year
>
> or
>
> do that in the SQL Statment using GROUP BY Clause
>
> --
>
> Bruno Alexandre
> (a Portuguese in Københanv, Danmark)
>
>
> "John" <(E-Mail Removed)> escreveu na mensagem
> news:(E-Mail Removed)...
>>I don't want the total in the footer. I want the total for each year like
>>this:
>> Sales 2006:
>> BMW 100
>> Lexus 75
>> Mercedes 70
>> Total Sales: 245
>> Sales 2005:
>> BMW 90
>> Lexus 40
>> Mercedes 10
>> Total Sales: 140
>>
>> I will be adding a total in the footer of all the totals, but for this I
>> want the totals as above.
>>
>>
>>
>>
>> "Bruno Alexandre" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> it's easy
>>>
>>> in one of the templates add the code
>>>
>>> <footerItem>
>>> <asp:label runat="server" id="lblTotal" text='<%= intTotal %>' />
>>> </footerItem>
>>>
>>> add
>>> Dim intTotal as Integer = 0
>>> at the begining of your script (outside Page_Load)
>>>
>>> you probably use a function to calculate the totals of the year, just
>>> add this line toyour code
>>>
>>> intTotal += yourBrandTotal
>>>
>>> If you are getting the total directly from the Database in a column
>>> named, for example, tTotal you problable have the code like this in your
>>> template item
>>>
>>> <asp:label runat="server" id="lblBrandTotal" Text='<%# Eval("tTotal")
>>> %>' />
>>>
>>>
>>> just it for this:
>>> <asp:label runat="server" id="lblBrandTotal" Text='<%# addTotal(
>>> Eval("tTotal") ) %>' />
>>>
>>> and ad a function called addTotal like:
>>>
>>> Function addTotal( myValue as integer ) as integer
>>> intTotal += myValue
>>> return myValue
>>> End function
>>>
>>> and that's it
>>>
>>> --
>>>
>>> Bruno Alexandre
>>> (a Portuguese in Københanv, Danmark)
>>>
>>>
>>> "John" <(E-Mail Removed)> escreveu na mensagem
>>> news:(E-Mail Removed)...
>>>> have a gridview where I need to add totals for each grouped data,
>>>>
>>>> example
>>>> my grid looks like this
>>>> Sales 2006:
>>>> BMW 100
>>>> Lexus 75
>>>> Mercedes 70
>>>> Total Sales: 245
>>>>
>>>> Sales 2005:
>>>> BMW 90
>>>> Lexus 40
>>>> Mercedes 10
>>>> Total Sales: 140
>>>>
>>>> I have the formatting done for all but the Total Sales row, how can I
>>>> add
>>>> that to my gridview?
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
Bruno Alexandre
Guest
Posts: n/a
 
      06-13-2006
ok...

(i don't have nothing, just the idea)

1. get the data from the SP to a SQLClient.DataReader
2. populate the GV with it
GridView.DataSource = dr
GridView.DataBind()
3. set a global variable to save the years (current row and previous row)
and the brand total
Public currentYear as string = ""
Public newYear as string = ""
Public totalForYear as integer = 0
4. in the GridView_DataBound you check if the year changed, imagine that you
present the year in a label
currentYear = ctype( gridview.findcontrol("myYearLabel", Label).Value
if oldYear <> currentYear then
the years are diferent, so Add a row here with the totals
else
oldYear = currentYear
totalForYear += cInt(ctype(gridview.findcontrol("myTotalBrandLabel ",
Label).Value)
end if
5. to add a new row with the variable follow this article for better view of
the idea:
http://fredrik.nsquared2.com/viewpost.aspx?PostID=201


with the data on SQLClient.DataReader you can add row by row manually and
check when the year changes so you can add a new row with totals, must like
classic ASP 3.0

--

Bruno Alexandre
(a Portuguese in Københanv, Danmark)


"John" <(E-Mail Removed)> escreveu na mensagem
news:(E-Mail Removed)...
> do u have a code snippet of something like this? I can't use the SQL
> (stored procedure) due to its used by other apps that don't want the data
> grouped or rolled up as I need to do on my web for
> "Bruno Alexandre" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> ok then,
>>
>> using the gridview_rowcreate you can add a row with the totals everytime
>> you change the year
>>
>> or
>>
>> do that in the SQL Statment using GROUP BY Clause
>>
>> --
>>
>> Bruno Alexandre
>> (a Portuguese in Københanv, Danmark)
>>
>>
>> "John" <(E-Mail Removed)> escreveu na mensagem
>> news:(E-Mail Removed)...
>>>I don't want the total in the footer. I want the total for each year
>>>like this:
>>> Sales 2006:
>>> BMW 100
>>> Lexus 75
>>> Mercedes 70
>>> Total Sales: 245
>>> Sales 2005:
>>> BMW 90
>>> Lexus 40
>>> Mercedes 10
>>> Total Sales: 140
>>>
>>> I will be adding a total in the footer of all the totals, but for this I
>>> want the totals as above.
>>>
>>>
>>>
>>>
>>> "Bruno Alexandre" <(E-Mail Removed)> wrote in message
>>> news:(E-Mail Removed)...
>>>> it's easy
>>>>
>>>> in one of the templates add the code
>>>>
>>>> <footerItem>
>>>> <asp:label runat="server" id="lblTotal" text='<%= intTotal %>' />
>>>> </footerItem>
>>>>
>>>> add
>>>> Dim intTotal as Integer = 0
>>>> at the begining of your script (outside Page_Load)
>>>>
>>>> you probably use a function to calculate the totals of the year, just
>>>> add this line toyour code
>>>>
>>>> intTotal += yourBrandTotal
>>>>
>>>> If you are getting the total directly from the Database in a column
>>>> named, for example, tTotal you problable have the code like this in
>>>> your template item
>>>>
>>>> <asp:label runat="server" id="lblBrandTotal" Text='<%# Eval("tTotal")
>>>> %>' />
>>>>
>>>>
>>>> just it for this:
>>>> <asp:label runat="server" id="lblBrandTotal" Text='<%# addTotal(
>>>> Eval("tTotal") ) %>' />
>>>>
>>>> and ad a function called addTotal like:
>>>>
>>>> Function addTotal( myValue as integer ) as integer
>>>> intTotal += myValue
>>>> return myValue
>>>> End function
>>>>
>>>> and that's it
>>>>
>>>> --
>>>>
>>>> Bruno Alexandre
>>>> (a Portuguese in Københanv, Danmark)
>>>>
>>>>
>>>> "John" <(E-Mail Removed)> escreveu na mensagem
>>>> news:(E-Mail Removed)...
>>>>> have a gridview where I need to add totals for each grouped data,
>>>>>
>>>>> example
>>>>> my grid looks like this
>>>>> Sales 2006:
>>>>> BMW 100
>>>>> Lexus 75
>>>>> Mercedes 70
>>>>> Total Sales: 245
>>>>>
>>>>> Sales 2005:
>>>>> BMW 90
>>>>> Lexus 40
>>>>> Mercedes 10
>>>>> Total Sales: 140
>>>>>
>>>>> I have the formatting done for all but the Total Sales row, how can I
>>>>> add
>>>>> that to my gridview?
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
add new row to gridview with totals Mike ASP .Net 3 02-21-2008 03:27 PM
Running totals in gridview (when you have many totals required) =?Utf-8?B?Um9iZXJ0IENoYXBtYW4=?= ASP .Net 3 02-16-2007 12:03 PM
Advice sought. How do I add summary row (not databound) to gridview. Like weekly totals etc dave ASP .Net 1 02-14-2007 08:15 PM
GridView Totals Row as First Row Walt Zydhek ASP .Net Datagrid Control 1 01-17-2007 04:20 AM
ok I can do a totals row but how about a percentage row after each data row D ASP .Net Datagrid Control 0 05-23-2005 04:10 PM



Advertisments