473,396 Members | 1,975 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,396 software developers and data experts.

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.ToString();

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 2001
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.findcontrol("Labelname")

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.ToString();

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.findcontrol("yourlablename")

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.ToString();

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.findcontrol("yourlablename")

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.ToString();

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.FindControl("txtTotalDollars"); //
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.findcontrol("Labelname")

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.ToString();

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("txtTotalDollars");

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****@discussions.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.FindControl("txtTotalDollars"); //
txtTotalDollars 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_ItemDataBound(object sender, DataGridItemEventArgs e)
{
Label lblDollars = (Label)e.Item.FindControl("txtTotalDollars");
lblDollars.Text = ttlDollars.ToString();
}

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.ToString();

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****@discussions.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_ItemDataBound(object sender, DataGridItemEventArgs e)
{
Label lblDollars = (Label)e.Item.FindControl("txtTotalDollars");
lblDollars.Text = ttlDollars.ToString();
}

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****@discussions.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_ItemDataBound(object sender, DataGridItemEventArgs e)
{
Label lblDollars = (Label)e.Item.FindControl("txtTotalDollars");
lblDollars.Text = ttlDollars.ToString();
}

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 += DataGridItemEventArgs(this.DataGrid1_ItemDataBound );

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****@discussions.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_ItemDataBound(object sender, DataGridItemEventArgs e)
{
Label lblDollars = (Label)e.Item.FindControl("txtTotalDollars");
lblDollars.Text = ttlDollars.ToString();
}

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
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...
0
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...
4
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...
4
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...
2
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
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,...
4
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...
0
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...
1
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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
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...
0
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,...

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.