Need to manipulate (Container.DataItem("mydbfield")) inside <itemtemplate>

Discussion in 'ASP .Net Web Controls' started by Chumley the Walrus, Jun 7, 2004.

  1. Inside a datalist, or repeater control <itemtemplate>, i'm trying to
    do an If statement with objects from my recordset :


    <% if (Container.DataItem("mydbfield")) <> "" then
    response.write(Container.DataItem("mydbfield2"))
    end if %>

    ...but i get a Container not declared error. It seems i can't
    manipulate these "containers" inside <itemtemplates>

    ???
    Chum
     
    Chumley the Walrus, Jun 7, 2004
    #1
    1. Advertisements

  2. Re: Need to manipulate (Container.DataItem("mydbfield")) inside<itemtemplate>

    Chumley the Walrus wrote:
    > Inside a datalist, or repeater control <itemtemplate>, i'm trying to
    > do an If statement with objects from my recordset :
    >
    >
    > <% if (Container.DataItem("mydbfield")) <> "" then
    > response.write(Container.DataItem("mydbfield2"))
    > end if %>
    >
    > ..but i get a Container not declared error. It seems i can't
    > manipulate these "containers" inside <itemtemplates>


    Call a "helper function" using the databinding syntax:

    <ItemTemplate>
    <%# SomeFunctionDefinedInCodeBehindClass(Container.DataItem("field")) %>
    </ItemTemplate>

    Then, in your code-behind class:

    Public Function SomeFunctionDefinedInCodeBehindClass(value as String) as
    String
    If value <> "" then
    Return value
    End If
    End Function


    For an example of using a helper function in a template see:
    http://datawebcontrols.com/faqs/CustomizingAppearance/CustomizeColumnValue.shtml

    Happy Programming!

    --

    Scott Mitchell

    http://www.4GuysFromRolla.com
    http://www.ASPMessageboard.com
    http://www.ASPFAQs.com

    * When you think ASP, think 4GuysFromRolla.com!
     
    Scott Mitchell [MVP], Jun 8, 2004
    #2
    1. Advertisements

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. Lauchlan M
    Replies:
    1
    Views:
    7,842
    Lauchlan M
    Oct 15, 2003
  2. Tom Lee
    Replies:
    2
    Views:
    994
    Chris Carter
    Dec 9, 2003
  3. Bennett Haselton
    Replies:
    1
    Views:
    5,623
    Joe Fallon
    Sep 24, 2004
  4. Dave
    Replies:
    1
    Views:
    472
    Mike Wahler
    Jan 22, 2005
  5. wolverine
    Replies:
    2
    Views:
    592
    Marcus Kwok
    Jul 24, 2006
  6. Replies:
    3
    Views:
    934
  7. Joe Rattz
    Replies:
    2
    Views:
    870
    Robert Koritnik
    Sep 10, 2004
  8. Didg
    Replies:
    1
    Views:
    187
Loading...