Results 1 to 4 of 4

Thread: Get Container.DataItem in Repeater on If Statement

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    3

    Get Container.DataItem in Repeater on If Statement

    I'm trying to use an if statement in a repeater to decide whether or not to display a field.
    Code:
    <% If DataBinder.Eval(Container.DataItem, "memtype") = "P" Then %>
    HTML TO SHOW A PICTURE
    <% End If %>
    I get an error saying Container isn't defined. I'm using a PagedDataSouce from a DataSet. Any ideas?

    Thanks, Aaron

  2. #2
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Re: Get Container.DataItem in Repeater on If Statement

    I'm guessing you have this if statement within the repeater itemtemplate.

    Best thing to do is call a method passing in arguments like so:
    Code:
    <%# displayImage( (string) DataBinder.Eval(Container.DataItem, "memtype") ) %>
    and then in the code behind:
    Code:
    string displayImage(string MemType) {
    if (MemType == "P") {
    //return string of HTML to display image
    }
    }
    Is that what you were after?

    DJ

    If I have been helpful please rate my post. If I haven't tell me!

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    3

    Re: Get Container.DataItem in Repeater on If Statement

    is there a way to do this in vb.net?

    I get the error "Overload resolution failed because no accessible 'ToString' can be called with these arguments"

    VB Code:
    1. <%# showDist(DataBinder.Eval(Container.DataItem, "distance"))%>

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    3

    Re: Get Container.DataItem in Repeater on If Statement

    Nevermind, I got it...thanks a lot

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width