If statements in asp repeater

J

Joachim Feldt

Hi,

To begin with, I should say that I am a beginner in the .Net world..

I am using asp:repeater in a aspx.page like this:
<asp:Repeater id="rptMyLabBooks" runat="server">
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.DataItem, "name")%></td>
<td><%# DataBinder.Eval(Container.DataItem,
"start_date","{0:d}")%></td>
<td><asp:Image id="imgIconOpen" runat="server"
ImageUrl="Images/icon_open.gif"></asp:Image></td>
<td><asp:HyperLink id="lnkEditLabBook"
ImageUrl="Images/icon_edit.gif" runat="server"
NavigateUrl="editlabBook.aspx"></asp:HyperLink></td>
<td><asp:HyperLink id="lnkViewLabBook"
ImageUrl="Images/icon_view.gif" runat="server"
NavigateUrl="viewlabBook.aspx"></asp:HyperLink></td>
</tr>
</ItemTemplate>

<HeaderTemplate>
<table cellpadding="3" cellspacing="0" border="0" width="740">
<tr>
<td class="listHeader" width="190">Author</td>
<td class="listHeader" width="100">Start date</td>
<td class="listHeader" width="40" align="center">Status</td>
<td class="listHeader" width="40" align="center">Edit</td>
<td class="listHeader" width="40" align="center">View</td>
</tr>
</HeaderTemplate>

<FooterTemplate>
</table>
</FooterTemplate>

</asp:Repeater>

No I need to have a couple of if statements here, I do not know how to
do that?
One statement would be in the column "Status". Something like this:

If myDataSet("status") = "Open" Then
sImage = "icon_open.gif"
ElseIf myDataSet("status") = "Closed" Then
sImage = "icon_closed.gif"
Else
sImage = "icon_archived.gif"
End If

How can I do this? Where do I put it, in Code behind?

I would be really happay if someone could give me an example!

Thanks in advance!

/Jocke
 
S

Scott Mitchell [MVP]

Joachim, you can use a "helper function" in the Template. You can see
an example here:
http://datawebcontrols.com/faqs/CustomizingAppearance/CustomizeColumnValue.shtml

This example uses a TemplateColumn in a DataGrid, but the concepts apply
to templates in DataLists and Repeaters as well.

Happy Programming!




Joachim said:
Hi,

To begin with, I should say that I am a beginner in the .Net world..

I am using asp:repeater in a aspx.page like this:
<asp:Repeater id="rptMyLabBooks" runat="server">
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.DataItem, "name")%></td>
<td><%# DataBinder.Eval(Container.DataItem,
"start_date","{0:d}")%></td>
<td><asp:Image id="imgIconOpen" runat="server"
ImageUrl="Images/icon_open.gif"></asp:Image></td>
<td><asp:HyperLink id="lnkEditLabBook"
ImageUrl="Images/icon_edit.gif" runat="server"
NavigateUrl="editlabBook.aspx"></asp:HyperLink></td>
<td><asp:HyperLink id="lnkViewLabBook"
ImageUrl="Images/icon_view.gif" runat="server"
NavigateUrl="viewlabBook.aspx"></asp:HyperLink></td>
</tr>
</ItemTemplate>

<HeaderTemplate>
<table cellpadding="3" cellspacing="0" border="0" width="740">
<tr>
<td class="listHeader" width="190">Author</td>
<td class="listHeader" width="100">Start date</td>
<td class="listHeader" width="40" align="center">Status</td>
<td class="listHeader" width="40" align="center">Edit</td>
<td class="listHeader" width="40" align="center">View</td>
</tr>
</HeaderTemplate>

<FooterTemplate>
</table>
</FooterTemplate>

</asp:Repeater>

No I need to have a couple of if statements here, I do not know how to
do that?
One statement would be in the column "Status". Something like this:

If myDataSet("status") = "Open" Then
sImage = "icon_open.gif"
ElseIf myDataSet("status") = "Closed" Then
sImage = "icon_closed.gif"
Else
sImage = "icon_archived.gif"
End If

How can I do this? Where do I put it, in Code behind?

I would be really happay if someone could give me an example!

Thanks in advance!

/Jocke


--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
 
J

Joachim Feldt

Thanks a lot! I think this will work.
Can I have this function(PrintGender in his example) in the code
behind instead? If so, how can I access it from the html mode?

Thanks again!

/Joachim
 
S

Scott Mitchell [MVP]

Joachim said:
Thanks a lot! I think this will work.
Can I have this function(PrintGender in his example) in the code
behind instead? If so, how can I access it from the html mode?

Sure, you can have it in the code-behind class for the page. Just make
sure to make the method Protected (or Public), like:

Protected PrintGender(gender as String) as String
...
End Function

hth

--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top