Results 1 to 5 of 5

Thread: Conditional Behavior with Databound repeater

  1. #1

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Question Conditional Behavior with Databound repeater

    VB Code:
    1. <%If Not DataBinder.Eval(Container.DataItem, "Discontinued") = True Then%>
    2. <a href="placeOrder.aspx?ProdID=<%# DataBinder.Eval(Container.DataItem,"ProductID")%>" style="text-decoration: none;">Order Now</a>
    3. <%Else%>
    4. Discontinued
    5. <%End If%>

    that code will not run. How do I get the same effect? I can't find away to get the data I need inside an if block....... I'm Using a Repetear bound to a DataSet and everything works fine if i take out the if block but I need it.....

    Thanks for any help you guys.
    Magiaus

    If I helped give me some points.

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Call a public function and return a string. Pass in your Discontinued variable. Something like this:
    Code:
    <% MyStringFunction(DataBinder.Eval(Container.DataItem, "Discontinued")) %>
    And your function:
    Code:
    Public Function MyStringFunction(ByVal obj as Object) As String
    
    If CType(obj, Boolean) = True Then
              MyStringFunction = "<a href="placeOrder.aspx?ProdID=<%# DataBinder.Eval(Container.DataItem,"ProductID")%>" style="text-decoration: none;">Order Now</a>"
    Else
              MyStringFunction = "Discontinued"
    End If
    End Function
    This was all done by hand and memory, so it may not work out of the box. But it is a good start in the direction you want to go. I have done this type of stuff myself.

  3. #3

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267
    I'll give that a try. I think the problem is that every where I have seen DataBinder used it <%# DataBinder%> I'll post and let you know if your idea works.
    Magiaus

    If I helped give me some points.

  4. #4
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    Usually, I do the following.

    Keep in mind that iif will probably be deprecated, but it's functionality could easily be duplicated with a user-written Function.

    ::

    <span style='<%#iif(Container.DataItem("Discontinued") , "display:none", "")%>'>
    MyStringFunction = "<a href="placeOrder.aspx?ProdID=<%# DataBinder.Eval(Container.DataItem,"ProductID")%>" style="text-decoration: none;">Order Now</a>"
    </span>

    <span style='<%#iif(not Container.DataItem("Discontinued") , "display:none", "")%>'>
    Discontinued
    </span>
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  5. #5

    Thread Starter
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267
    i see say the blind man
    Magiaus

    If I helped give me some points.

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