Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Showing datagrid totals in the footer

Reply
Thread Tools

Showing datagrid totals in the footer

 
 
=?Utf-8?B?SnVzdGlu?=
Guest
Posts: n/a
 
      10-14-2004
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.
 
Reply With Quote
 
 
 
 
=?Utf-8?B?U2FyYXZhbmE=?=
Guest
Posts: n/a
 
      10-14-2004
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.

 
Reply With Quote
 
 
 
 
=?Utf-8?B?U2FyYXZhbmE=?=
Guest
Posts: n/a
 
      10-14-2004
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.

 
Reply With Quote
 
=?Utf-8?B?U2FyYXZhbmE=?=
Guest
Posts: n/a
 
      10-14-2004
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.

 
Reply With Quote
 
=?Utf-8?B?SnVzdGlu?=
Guest
Posts: n/a
 
      10-14-2004
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.

 
Reply With Quote
 
Scott Allen
Guest
Posts: n/a
 
      10-14-2004
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
<(E-Mail Removed)> 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.
>



 
Reply With Quote
 
=?Utf-8?B?SnVzdGlu?=
Guest
Posts: n/a
 
      10-14-2004
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.

 
Reply With Quote
 
Scott Allen
Guest
Posts: n/a
 
      10-15-2004
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
<(E-Mail Removed)> 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.
>


 
Reply With Quote
 
=?Utf-8?B?SnVzdGlu?=
Guest
Posts: n/a
 
      10-15-2004
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
> <(E-Mail Removed)> 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.
> >

>
>

 
Reply With Quote
 
=?Utf-8?B?SnVzdGlu?=
Guest
Posts: n/a
 
      10-15-2004
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
> <(E-Mail Removed)> 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.
> >

>
>

 
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
Running totals in gridview (when you have many totals required) =?Utf-8?B?Um9iZXJ0IENoYXBtYW4=?= ASP .Net 3 02-16-2007 12:03 PM
footer totals mark ASP .Net 3 09-07-2004 03:21 PM
NEWBIE - Column Totals in Footer of mxDataGrid RockNRoll ASP .Net Datagrid Control 3 08-13-2004 12:21 AM
Error trying to get totals in footer ASP .Net 2 07-02-2004 05:42 PM
Totals in grid footer? SStory ASP .Net Datagrid Control 3 05-14-2004 04:11 AM



Advertisments