473,769 Members | 5,374 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Showing datagrid totals in the footer

I am trying to figure out how to display the sum total of a numeric column in
the footer of a datagrid. I have tried putting a label control in the footer
of a column but for some reason when I try to reference the label control
using:

txtTotalDollars .Text = ttlDollars.ToSt ring();

I get an error saying that the label control txtTotalDollars does not exist.
Note that when I place the label outside of the footer it works fine.

Any ideas?

Thanks, Justin.
Nov 18 '05 #1
9 2029
If you add any controls inside datagrid (either in footer or header). it will
be placed under controls collection of datagrid. So if you try to directly
access the control, you will get error like this. If you want to set some
value to that label or if you want to access that label. then you need to do
this

datagriditem.fi ndcontrol("Labe lname")

Check out this article for more info,
http://www.extremeexperts.com/Net/Ar...stoFooter.aspx

"Justin" wrote:
I am trying to figure out how to display the sum total of a numeric column in
the footer of a datagrid. I have tried putting a label control in the footer
of a column but for some reason when I try to reference the label control
using:

txtTotalDollars .Text = ttlDollars.ToSt ring();

I get an error saying that the label control txtTotalDollars does not exist.
Note that when I place the label outside of the footer it works fine.

Any ideas?

Thanks, Justin.

Nov 18 '05 #2
You need to access any controls inside datagrid using following syntax.
datagriditem.fi ndcontrol("your lablename")

for more deatils check out this article,
http://www.extremeexperts.com/Net/Ar...stoFooter.aspx
"Justin" wrote:
I am trying to figure out how to display the sum total of a numeric column in
the footer of a datagrid. I have tried putting a label control in the footer
of a column but for some reason when I try to reference the label control
using:

txtTotalDollars .Text = ttlDollars.ToSt ring();

I get an error saying that the label control txtTotalDollars does not exist.
Note that when I place the label outside of the footer it works fine.

Any ideas?

Thanks, Justin.

Nov 18 '05 #3
You need to access any controls inside datagrid using following syntax.
datagriditem.fi ndcontrol("your lablename")

for more deatils check out this article,
http://www.extremeexperts.com/Net/Ar...stoFooter.aspx
"Justin" wrote:
I am trying to figure out how to display the sum total of a numeric column in
the footer of a datagrid. I have tried putting a label control in the footer
of a column but for some reason when I try to reference the label control
using:

txtTotalDollars .Text = ttlDollars.ToSt ring();

I get an error saying that the label control txtTotalDollars does not exist.
Note that when I place the label outside of the footer it works fine.

Any ideas?

Thanks, Justin.

Nov 18 '05 #4
Can you or someone else ellaborate a little more on how to accomplish this
task? The article was of little help.

I have this so far: DataGrid1.FindC ontrol("txtTota lDollars"); //
txtTotalDollars is the label

I am unable to asign a value to that code. How can I do that?

Thanks, Justin.

"Saravana" wrote:
If you add any controls inside datagrid (either in footer or header). it will
be placed under controls collection of datagrid. So if you try to directly
access the control, you will get error like this. If you want to set some
value to that label or if you want to access that label. then you need to do
this

datagriditem.fi ndcontrol("Labe lname")

Check out this article for more info,
http://www.extremeexperts.com/Net/Ar...stoFooter.aspx

"Justin" wrote:
I am trying to figure out how to display the sum total of a numeric column in
the footer of a datagrid. I have tried putting a label control in the footer
of a column but for some reason when I try to reference the label control
using:

txtTotalDollars .Text = ttlDollars.ToSt ring();

I get an error saying that the label control txtTotalDollars does not exist.
Note that when I place the label outside of the footer it works fine.

Any ideas?

Thanks, Justin.

Nov 18 '05 #5
Hi Justin:

FindControl has to be called on the DataGridItem that contains the
textbox. The DataGridItem you want is the footer, and probably the
last one in the Item array

DataGrid.Items[DataGrid.Items. Count-1].Findcontrol("t xtTotalDollars" );

For more info:
http://odetocode.com/Articles/116.aspx

--
Scott
http://www.OdeToCode.com/blogs/scott/
On Thu, 14 Oct 2004 01:39:06 -0700, Justin
<Ju****@discuss ions.microsoft. com> wrote:
Can you or someone else ellaborate a little more on how to accomplish this
task? The article was of little help.

I have this so far: DataGrid1.FindC ontrol("txtTota lDollars"); //
txtTotalDollar s is the label

I am unable to asign a value to that code. How can I do that?

Thanks, Justin.

Nov 18 '05 #6
Ok, I seem to have the correct code but for some reason nothing is showing up
in the label.

Here is my code:

protected void DataGrid1_ItemD ataBound(object sender, DataGridItemEve ntArgs e)
{
Label lblDollars = (Label)e.Item.F indControl("txt TotalDollars");
lblDollars.Text = ttlDollars.ToSt ring();
}

Any ideas?

Thanks, for the help.

Justin.

"Justin" wrote:
I am trying to figure out how to display the sum total of a numeric column in
the footer of a datagrid. I have tried putting a label control in the footer
of a column but for some reason when I try to reference the label control
using:

txtTotalDollars .Text = ttlDollars.ToSt ring();

I get an error saying that the label control txtTotalDollars does not exist.
Note that when I place the label outside of the footer it works fine.

Any ideas?

Thanks, Justin.

Nov 18 '05 #7
Hi Justin:

That snippet of code looks entirely reasonable. Have you set a
breakpoint with the deubgger? Any chance of ttlDollars being an empty
string?

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Thu, 14 Oct 2004 14:59:03 -0700, Justin
<Ju****@discuss ions.microsoft. com> wrote:
Ok, I seem to have the correct code but for some reason nothing is showing up
in the label.

Here is my code:

protected void DataGrid1_ItemD ataBound(object sender, DataGridItemEve ntArgs e)
{
Label lblDollars = (Label)e.Item.F indControl("txt TotalDollars");
lblDollars.Tex t = ttlDollars.ToSt ring();
}

Any ideas?

Thanks, for the help.

Justin.


Nov 18 '05 #8
I tested ttlDollars on another non datagrid label and it works fine, so the
variable is not empty, I must be using findcontrol on the wrong item.

"Scott Allen" wrote:
Hi Justin:

That snippet of code looks entirely reasonable. Have you set a
breakpoint with the deubgger? Any chance of ttlDollars being an empty
string?

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Thu, 14 Oct 2004 14:59:03 -0700, Justin
<Ju****@discuss ions.microsoft. com> wrote:
Ok, I seem to have the correct code but for some reason nothing is showing up
in the label.

Here is my code:

protected void DataGrid1_ItemD ataBound(object sender, DataGridItemEve ntArgs e)
{
Label lblDollars = (Label)e.Item.F indControl("txt TotalDollars");
lblDollars.Tex t = ttlDollars.ToSt ring();
}

Any ideas?

Thanks, for the help.

Justin.


Nov 18 '05 #9
Ok, I think I found the solution. It is in the way I am wiring up the event,
heres what I am doing now:

this.DataGrid1 += DataGridItemEve ntArgs(this.Dat aGrid1_ItemData Bound);

I can't think of any other way to wire it up. Any suggestions?

Thanks, Justin.

"Scott Allen" wrote:
Hi Justin:

That snippet of code looks entirely reasonable. Have you set a
breakpoint with the deubgger? Any chance of ttlDollars being an empty
string?

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Thu, 14 Oct 2004 14:59:03 -0700, Justin
<Ju****@discuss ions.microsoft. com> wrote:
Ok, I seem to have the correct code but for some reason nothing is showing up
in the label.

Here is my code:

protected void DataGrid1_ItemD ataBound(object sender, DataGridItemEve ntArgs e)
{
Label lblDollars = (Label)e.Item.F indControl("txt TotalDollars");
lblDollars.Tex t = ttlDollars.ToSt ring();
}

Any ideas?

Thanks, for the help.

Justin.


Nov 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1795
by: Steve | last post by:
Hi, I have xml data containing "line item" elements and a "footer" element which contains control totals for the line items. While I can easily validate the control totals in xslt, I have not been able to do it using a schema, which I need to do. Example: <data> <item><fld1>1</fld2><fld2>2</fld2></item>
0
1165
by: MrNobody | last post by:
I am desperately in need of some help to get a summary row for my DataGrid. A summary row is just a row always on the bottom which has totals for certain columns. I have been able to find tutorials online that show exactly how to accomplish this using the Web UI DataGrid in ASP.net, but unfortunately the DataGrids are simply not the same- the Windows.Forms DataGrid does not have a footer you can use like the Web UI one has So far the...
4
1659
by: JJ | last post by:
Hi, I am using a datagrid to display employee time sheets and need a running total for datagrid. So I am wondering since I am displaying totals in footer, should I use maybe a new datalist or datagrid for new records? So basically have 2 grids one for updates and the other for new records? If so should I use a panel so that in update mode it would hide the new records grid and vice versa? What do you guys think would look and work the...
4
1033
by: coleenholley | last post by:
I have an ASP table that I need to convert to a datagrid, but I have calulations like this: row1.cell1(column1) X row1.cell2(column2) = row1.cell3(column3) I also need to get grand totals in the footer - I've found articles on how to do this in VB, so am good to go with the grand totals, but I have not had any luck finding articles with examples in VB on how to do calculations across a row in a datagrid. I REALLY need an GOOD...
2
2621
by: Marcin | last post by:
Hello! How to I can create a summary row in DataGrid in Visual C# .NET or VB.NET? In ASP.NET available Footer for DataGrid, but in VC# I can't find this. -- with regards, Marcin
1
1996
by: .Net Sports | last post by:
the below itemdatabound function works , displays all the grand totals in the footer control of the datagrid: private void dglvboard_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { DataRowView rowData; decimal price; decimal priceWk; decimal newssum;
4
5660
by: Micheal | last post by:
Greetings Access Group, Being relatively new to Access, I try to work through problems on my own and have been very successful, although I have a conundrum that I have been working on for two days (total 10 hours) and I have yet to resolve it. please excuse me for my lack of terminology, I will try to provide you with the best of information. I currently have a report that contains 2 totals and the percentage of the difference of the 2...
0
2110
by: Josetta | last post by:
Here is something really bizarre that is happening...let me see if I can describe it. I have a report which has two locations on it. Primary Location and Secondary Location. I have both locations grouped. For example: Primary Location (group header 1) is a city. Secondary Location (group header 2) is a Street Address.
1
1791
by: csolomon | last post by:
Happy Friday! I was wondering if you can have more than one total in the footer. I ask this because when I set up one of my totals in the footer (lets call it total1), it works (slowly but it works)...but when I set up the other one (total2), I get an error for the total1 value and an error for the total2 value. I have a function, GetYield, that returns a calculation based on the material chosen (matType). Public Function...
0
9589
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
10214
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8872
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...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3963
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
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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.