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. Advertising

  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. 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. Bennett Haselton
    Replies:
    1
    Views:
    5,348
    Joe Fallon
    Sep 24, 2004
  2. Dave
    Replies:
    1
    Views:
    331
    Mike Wahler
    Jan 22, 2005
  3. Replies:
    3
    Views:
    814
  4. Joe Rattz
    Replies:
    2
    Views:
    605
    Robert Koritnik
    Sep 10, 2004
  5. Didg
    Replies:
    1
    Views:
    116
Loading...

Share This Page