Accessing the DataList footer in ASP.NET

Discussion in 'ASP .Net' started by amiga500@gmail.com, Oct 16, 2007.

  1. Guest

    Hello,

    I have a DataList that displays the item information and total price
    of each time but I want to add a footer with a complete subtotal. I am
    using ASP.NET (VB) however I don't know how to call a footer in my
    code, below is the code I have added:

    CType(e.Item.FindControl("lblFooterTotal"), Label).Text =
    CompleteTotal

    However I get this "Object reference not set to an instance of an
    object." because it cannot find the footer. Here is the HTML code:

    <FooterTemplate>
    <asp:Label ID ="lblCompleteTotal" runat =
    "server">Total:</asp:Label>
    <asp:Label ID="lblFooterTotal" runat="server"
    Text="0"></asp:Label>
    </FooterTemplate>

    Can someone please help me in this regard? Thanks in advance.
    , Oct 16, 2007
    #1
    1. Advertising

  2. Check if e.Item.ItemType = ListItemType.Footer before trying to access
    footer controls.

    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    <> wrote in message
    news:...
    > Hello,
    >
    > I have a DataList that displays the item information and total price
    > of each time but I want to add a footer with a complete subtotal. I am
    > using ASP.NET (VB) however I don't know how to call a footer in my
    > code, below is the code I have added:
    >
    > CType(e.Item.FindControl("lblFooterTotal"), Label).Text =
    > CompleteTotal
    >
    > However I get this "Object reference not set to an instance of an
    > object." because it cannot find the footer. Here is the HTML code:
    >
    > <FooterTemplate>
    > <asp:Label ID ="lblCompleteTotal" runat =
    > "server">Total:</asp:Label>
    > <asp:Label ID="lblFooterTotal" runat="server"
    > Text="0"></asp:Label>
    > </FooterTemplate>
    >
    > Can someone please help me in this regard? Thanks in advance.
    >
    Eliyahu Goldin, Oct 16, 2007
    #2
    1. Advertising

  3. Hi,

    I assuming , you written "CType(e.Item.FindControl("lblFooterTotal"),
    Label).Text =
    CompleteTotal" code in DataList_ItemDataBound.

    Try this
    If e.Item.ItemType = ListItemType.Footer Then
    CType(e.Item.FindControl("lblTotalPercentage"), Label) ).Text =
    CompleteTotal
    End If

    "" wrote:

    > Hello,
    >
    > I have a DataList that displays the item information and total price
    > of each time but I want to add a footer with a complete subtotal. I am
    > using ASP.NET (VB) however I don't know how to call a footer in my
    > code, below is the code I have added:
    >
    > CType(e.Item.FindControl("lblFooterTotal"), Label).Text =
    > CompleteTotal
    >
    > However I get this "Object reference not set to an instance of an
    > object." because it cannot find the footer. Here is the HTML code:
    >
    > <FooterTemplate>
    > <asp:Label ID ="lblCompleteTotal" runat =
    > "server">Total:</asp:Label>
    > <asp:Label ID="lblFooterTotal" runat="server"
    > Text="0"></asp:Label>
    > </FooterTemplate>
    >
    > Can someone please help me in this regard? Thanks in advance.
    >
    >
    =?Utf-8?B?VWp2YWwgU2hhaA==?=, Oct 16, 2007
    #3
  4. Guest

    On Oct 16, 10:44 am, Ujval Shah <>
    wrote:
    > Hi,
    >
    > I assuming , you written "CType(e.Item.FindControl("lblFooterTotal"),
    > Label).Text =
    > CompleteTotal" code in DataList_ItemDataBound.
    >
    > Try this
    > If e.Item.ItemType = ListItemType.Footer Then
    > CType(e.Item.FindControl("lblTotalPercentage"), Label) ).Text =
    > CompleteTotal
    > End If
    >
    > "" wrote:
    > > Hello,

    >
    > > I have a DataList that displays the item information and total price
    > > of each time but I want to add a footer with a complete subtotal. I am
    > > using ASP.NET (VB) however I don't know how to call a footer in my
    > > code, below is the code I have added:

    >

    Thank you guys, much appreciate it :D

    > > CType(e.Item.FindControl("lblFooterTotal"), Label).Text =
    > > CompleteTotal

    >
    > > However I get this "Object reference not set to an instance of an
    > > object." because it cannot find the footer. Here is the HTML code:

    >
    > > <FooterTemplate>
    > > <asp:Label ID ="lblCompleteTotal" runat =
    > > "server">Total:</asp:Label>
    > > <asp:Label ID="lblFooterTotal" runat="server"
    > > Text="0"></asp:Label>
    > > </FooterTemplate>

    >
    > > Can someone please help me in this regard? Thanks in advance.
    , Oct 16, 2007
    #4
    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. KathyB
    Replies:
    1
    Views:
    424
  2. Paul Maidment
    Replies:
    1
    Views:
    4,371
    Nick Berardi
    Aug 7, 2003
  3. Chris

    Button in Datalist Footer Error...

    Chris, Aug 9, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    2,625
    Rick Spiewak
    Aug 11, 2004
  4. Nevyn Twyll
    Replies:
    8
    Views:
    1,848
  5. Henrik
    Replies:
    1
    Views:
    417
    Ken Cox [Microsoft MVP]
    Jul 6, 2006
Loading...

Share This Page