Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Contional testing in ItemTemplate of Repeater

Reply
Thread Tools

Contional testing in ItemTemplate of Repeater

 
 
matt
Guest
Posts: n/a
 
      02-02-2004
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>


 
Reply With Quote
 
 
 
 
matt
Guest
Posts: n/a
 
      02-03-2004
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>
>
>



 
Reply With Quote
 
 
 
 
Alessandro Zifiglio
Guest
Posts: n/a
 
      02-03-2004
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>
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET: Repeater: RadioButtons in ItemTemplate Sachin ASP .Net 1 02-21-2006 08:47 PM
Changing Repeater ItemTemplate details based on data from dataset Mike ASP .Net 1 02-04-2006 08:32 AM
multiple <td> in a repeater control <ItemTemplate> (asp.net 2) webserverpete@ebtech.net ASP .Net 3 08-16-2005 01:43 PM
Repeater.ItemTemplate =? Shimon Sim ASP .Net 1 01-27-2005 11:34 PM
can code inside a Repeater's ItemTemplate modify controls in the ItemTemplate? Bennett Haselton ASP .Net 1 09-24-2004 01:59 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57