Showing datagrid totals in the footer

Discussion in 'ASP .Net' started by =?Utf-8?B?SnVzdGlu?=, Oct 14, 2004.

  1. 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.
    =?Utf-8?B?SnVzdGlu?=, Oct 14, 2004
    #1
    1. Advertising

  2. 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/Articles/AddingControlstoFooter.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.
    =?Utf-8?B?U2FyYXZhbmE=?=, Oct 14, 2004
    #2
    1. Advertising

  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/Articles/AddingControlstoFooter.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.
    =?Utf-8?B?U2FyYXZhbmE=?=, Oct 14, 2004
    #3
  4. 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/Articles/AddingControlstoFooter.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.
    =?Utf-8?B?U2FyYXZhbmE=?=, Oct 14, 2004
    #4
  5. 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/Articles/AddingControlstoFooter.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.
    =?Utf-8?B?SnVzdGlu?=, Oct 14, 2004
    #5
  6. =?Utf-8?B?SnVzdGlu?=

    Scott Allen Guest

    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
    <> 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.
    >
    Scott Allen, Oct 14, 2004
    #6
  7. 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.
    =?Utf-8?B?SnVzdGlu?=, Oct 14, 2004
    #7
  8. =?Utf-8?B?SnVzdGlu?=

    Scott Allen Guest

    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
    <> 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.
    >
    Scott Allen, Oct 15, 2004
    #8
  9. 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
    > <> 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.
    > >

    >
    >
    =?Utf-8?B?SnVzdGlu?=, Oct 15, 2004
    #9
  10. 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
    > <> 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.
    > >

    >
    >
    =?Utf-8?B?SnVzdGlu?=, Oct 15, 2004
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    2
    Views:
    443
    Guest
    Jul 2, 2004
  2. mark

    footer totals

    mark, Sep 7, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    485
    Greg Burns
    Sep 7, 2004
  3. =?Utf-8?B?Um9iZXJ0IENoYXBtYW4=?=

    Running totals in gridview (when you have many totals required)

    =?Utf-8?B?Um9iZXJ0IENoYXBtYW4=?=, Feb 15, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    856
    Alexey Smirnov
    Feb 16, 2007
  4. SStory

    Totals in grid footer?

    SStory, May 11, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    3
    Views:
    167
    Saravana [MVP]
    May 14, 2004
  5. RockNRoll

    NEWBIE - Column Totals in Footer of mxDataGrid

    RockNRoll, Aug 12, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    3
    Views:
    148
    Alvin Bruney [MVP]
    Aug 13, 2004
Loading...

Share This Page