Contional testing in ItemTemplate of Repeater

Discussion in 'ASP .Net Web Controls' started by matt, Feb 2, 2004.

  1. matt

    matt Guest

    I wanted to conditionally show an IMG based on values in the Repeater
    record. Here is the code I am trying to implement...this does not work
    because it does not like the Container object in this context.

    <itemtemplate>
    <tr>
    <td class="tsbody" align="left" valign="middle" bgcolor="#efefef">
    &nbsp;<%# DataBinder.Eval(Container.DataItem, "StrDrugDesc") %>&nbsp;
    </td>
    <td class="tsbody" align="left" valign="middle" bgcolor="#efefef">
    &nbsp;<b><%# DataBinder.Eval(Container.DataItem, "PrescriptNo")
    %></b>&nbsp;
    </td>
    <td class="tsbody" align="center" valign="middle" bgcolor="#efefef">
    <%
    ' **** PROBLEM HERE ****
    Dim str as string = DataBinder.Eval(Container.DataItem, "DtmCompleted")
    Dim str1 as string = DataBinder.Eval(Container.DataItem,
    "DtmReturnedToInv")

    ' Only show if not completed and not returned
    If (not (str is nothing) and not (str1 is nothing)) Then
    %>
    <img width="40" height="40" border="0"
    src="../../images/touchscreen/verify_off.gif"
    name="img<%# DataBinder.Eval(Container.DataItem, "StrCode") %>"
    id="img<%# DataBinder.Eval(Container.DataItem, "StrCode") %>"
    onclick="javascript:selectCustomer('<%#
    DataBinder.Eval(Container.DataItem, "StrCode") %>');"
    <% End If %>
    />
    </td>
    </tr>
    </itemtemplate>
     
    matt, Feb 2, 2004
    #1
    1. Advertising

  2. matt

    matt Guest

    Re: Contional testing in ItemTemplate of Repeater..MVP help Please

    Since I didn't get any responses yet, maybe I should rephrase the question
    because I think this has to be a common functionality for web developers.

    I am trying to show/hide an image in a table column based on a value in
    underlying row's datarow. I am using the asp:Repeater because I am
    displaying hierarchical data and it seemed the easiest to format with. The
    image, when clicked, needs to fire a clientside javascript function.

    I tried creating HtmlImage controls on the fly in the Repeater's
    onitemcreated event. But, I haven't figured out how to get the image inside
    the column I want because the <TD>'s are not set to runat "server". I
    cannot locate the <TD> in the e.Item.Controls object.

    Any Ideas?

    Thanks a bunch, I'm really in a crunch now.

    "matt" <> wrote in message
    news:%...
    > I wanted to conditionally show an IMG based on values in the Repeater
    > record. Here is the code I am trying to implement...this does not work
    > because it does not like the Container object in this context.
    >
    > <itemtemplate>
    > <tr>
    > <td class="tsbody" align="left" valign="middle" bgcolor="#efefef">
    > &nbsp;<%# DataBinder.Eval(Container.DataItem, "StrDrugDesc") %>&nbsp;
    > </td>
    > <td class="tsbody" align="left" valign="middle" bgcolor="#efefef">
    > &nbsp;<b><%# DataBinder.Eval(Container.DataItem, "PrescriptNo")
    > %></b>&nbsp;
    > </td>
    > <td class="tsbody" align="center" valign="middle" bgcolor="#efefef">
    > <%
    > ' **** PROBLEM HERE ****
    > Dim str as string = DataBinder.Eval(Container.DataItem, "DtmCompleted")
    > Dim str1 as string = DataBinder.Eval(Container.DataItem,
    > "DtmReturnedToInv")
    >
    > ' Only show if not completed and not returned
    > If (not (str is nothing) and not (str1 is nothing)) Then
    > %>
    > <img width="40" height="40" border="0"
    > src="../../images/touchscreen/verify_off.gif"
    > name="img<%# DataBinder.Eval(Container.DataItem, "StrCode") %>"
    > id="img<%# DataBinder.Eval(Container.DataItem, "StrCode") %>"
    > onclick="javascript:selectCustomer('<%#
    > DataBinder.Eval(Container.DataItem, "StrCode") %>');"
    > <% End If %>
    > />
    > </td>
    > </tr>
    > </itemtemplate>
    >
    >
     
    matt, Feb 3, 2004
    #2
    1. Advertising

  3. Re: Contional testing in ItemTemplate of Repeater..MVP help Please

    hi matt,
    I see you are still stuck with classic asp ;P

    In asp.net you do not declare code blocks anywhere in your hmtl and perform
    evaluations ;)

    This is the way to go :

    in your codebehind class you need to write your function :
    Function DisplayImage(ByVal DtmCompleted As string, ByVal DtmReturnedToInv
    As string,ByVal strCode as string) As String
    ' Do your evaluation here and then return your string
    Return "<img style=""width:40px;height:40px;border:0px""
    src=""../../images/touchscreen/verify_off.gif"" name=""img" & strcode & """
    id=""img" & strcode & """ onclick=""javascript:selectCustomer('" & strcode &
    "');""" & " />"
    End Function



    then call it in your repeater like this :

    <itemtemplate>
    <tr>
    <td class="tsbody" align="left" valign="middle" bgcolor="#efefef">
    &nbsp;<%# DataBinder.Eval(Container.DataItem, "StrDrugDesc") %>&nbsp;
    </td>
    <td class="tsbody" align="left" valign="middle" bgcolor="#efefef">
    &nbsp;<b><%# DataBinder.Eval(Container.DataItem, "PrescriptNo")
    %></b>&nbsp;
    </td>
    <td class="tsbody" align="center" valign="middle" bgcolor="#efefef">

    <asp:Literal id="Literal1" text='<%# DisplayImage(DataBinder.Eval(Container,
    "DataItem.DtmCompleted"), DataBinder.Eval(Container,
    "DataItem.DtmReturnedToInv"), DataBinder.Eval(Container,
    "DataItem.StrCode")) %>' runat="server"></asp:Literal>

    </td>
    </tr>
    </itemtemplate>


    I have used a literal control here and am supply the return value from your
    function to its text value.




    "matt" <> wrote in message
    news:...
    > Since I didn't get any responses yet, maybe I should rephrase the question
    > because I think this has to be a common functionality for web developers.
    >
    > I am trying to show/hide an image in a table column based on a value in
    > underlying row's datarow. I am using the asp:Repeater because I am
    > displaying hierarchical data and it seemed the easiest to format with.

    The
    > image, when clicked, needs to fire a clientside javascript function.
    >
    > I tried creating HtmlImage controls on the fly in the Repeater's
    > onitemcreated event. But, I haven't figured out how to get the image

    inside
    > the column I want because the <TD>'s are not set to runat "server". I
    > cannot locate the <TD> in the e.Item.Controls object.
    >
    > Any Ideas?
    >
    > Thanks a bunch, I'm really in a crunch now.
    >
    > "matt" <> wrote in message
    > news:%...
    > > I wanted to conditionally show an IMG based on values in the Repeater
    > > record. Here is the code I am trying to implement...this does not work
    > > because it does not like the Container object in this context.
    > >
    > > <itemtemplate>
    > > <tr>
    > > <td class="tsbody" align="left" valign="middle" bgcolor="#efefef">
    > > &nbsp;<%# DataBinder.Eval(Container.DataItem, "StrDrugDesc") %>&nbsp;
    > > </td>
    > > <td class="tsbody" align="left" valign="middle" bgcolor="#efefef">
    > > &nbsp;<b><%# DataBinder.Eval(Container.DataItem, "PrescriptNo")
    > > %></b>&nbsp;
    > > </td>
    > > <td class="tsbody" align="center" valign="middle" bgcolor="#efefef">
    > > <%
    > > ' **** PROBLEM HERE ****
    > > Dim str as string = DataBinder.Eval(Container.DataItem,

    "DtmCompleted")
    > > Dim str1 as string = DataBinder.Eval(Container.DataItem,
    > > "DtmReturnedToInv")
    > >
    > > ' Only show if not completed and not returned
    > > If (not (str is nothing) and not (str1 is nothing)) Then
    > > %>
    > > <img width="40" height="40" border="0"
    > > src="../../images/touchscreen/verify_off.gif"
    > > name="img<%# DataBinder.Eval(Container.DataItem, "StrCode") %>"
    > > id="img<%# DataBinder.Eval(Container.DataItem, "StrCode") %>"
    > > onclick="javascript:selectCustomer('<%#
    > > DataBinder.Eval(Container.DataItem, "StrCode") %>');"
    > > <% End If %>
    > > />
    > > </td>
    > > </tr>
    > > </itemtemplate>
    > >
    > >

    >
    >
     
    Alessandro Zifiglio, Feb 3, 2004
    #3
    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,344
    Joe Fallon
    Sep 24, 2004
  2. Shimon Sim

    Repeater.ItemTemplate =?

    Shimon Sim, Jan 27, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    958
    Karl Seguin
    Jan 27, 2005
  3. Replies:
    3
    Views:
    1,604
    Eliyahu Goldin
    Aug 16, 2005
  4. Mike
    Replies:
    1
    Views:
    608
    Alec MacLean
    Feb 4, 2006
  5. Sachin
    Replies:
    1
    Views:
    1,194
    sloan
    Feb 21, 2006
Loading...

Share This Page