using a condition in a repeater control

B

Bernie V

Hi group,

Is it possible to use a condition in a repeater control ?
I 'd like to use a condition to create this <a
href='<%#DataBinder.Eval(Container.DataItem,"nieuwsid")%>.aspx'> part of
the repeater
At the moment I use "nieuwsid" to make the url but in some cases it has to
be <a href='wcharts.aspx'>

Is that possible ?
This is my full repeater code at the moment:

<asp:repeater id="NewsRepeater" runat="server">
<headertemplate>
<table style="WIDTH: 144px" cellSpacing="0" cols="1"
borderColorDark="gainsboro" cellPadding="0"
width="144" borderColorLight="whitesmoke" border="0">
<TR class="Hoofdpunten">
<asp:label id="LabelNieuws" CssClass="Hoofdpunten" runat="server"
Height="12">NIEUWS</asp:label></TR>
</headertemplate>
<itemtemplate>
<tr class="DatNieuws">
<%# DataBinder.Eval(Container.DataItem,"datum","{0:dd/MM/yyyy}")%>
</tr>
<tr class="Nieuws">
<img src=".\images\icon_news.gif" align="left"> <a
href='<%#DataBinder.Eval(Container.DataItem,"nieuwsid")%>.aspx'>
<%# DataBinder.Eval(Container.DataItem,"titel")%>
</a>
</tr>
</itemtemplate>
<footertemplate>
</table>
</footertemplate>
</asp:repeater>


thx in advance !
grz

Bernie V
 
S

Stefano Mostarda

Hi Bernie,

Instead of using an expression put an hyperlink object within the <tr>
tags and set his link(not the real name, but can't remember the right
one) property in the databound event of the repeater.

Hope this helps.

Stefano Mostarda MCP
Rome Italy.
 
S

SSW

Yes u can do it.

Replace Below
<img src=".\images\icon_news.gif" align="left"> <a
href='<%#DataBinder.Eval(Container.DataItem,"nieuwsid")%>.aspx'>
with
<img src=".\images\icon_news.gif" align="left"> <a
href='<%#(URConditions)?DataBinder.Eval(Container.DataItem,"nieuwsid"):DataB
inder.Eval(Container.DataItem,"wcharts.aspx")%>.aspx'>
in ur aspx code
Please don't forget to replace URConditions with some condition which could
be evaluated.

I had tried below as sample and it works, So u can try on same line...

<asp:Repeater id="RP1" runat="server">
<ItemTemplate>
<%#DateTime.Now.Second>=30?DateTime.Now.ToString():"NoDate"%><br>
</ItemTemplate>
<HeaderTemplate>
ABC<br>
</HeaderTemplate>
</asp:Repeater>

Yes I had also binded the RP1 in Code behind
DataTable dt = new DataTable("EX");
DataColumn dc = new DataColumn("Hello",
System.Type.GetType("System.String"));
dt.Columns.Add(dc);
DataRow dr = dt.NewRow();
dr["Hello"]="Hello";
dt.Rows.Add( dr );
RP1.DataSource = dt;
RP1.DataBind();

HTH...

Thanks,

sswalia
MCSD, MCAD, OCA
 
B

Bernie V

SSW said:
I had tried below as sample and it works, So u can try on same line...

<asp:Repeater id="RP1" runat="server">
<ItemTemplate>
<%#DateTime.Now.Second>=30?DateTime.Now.ToString():"NoDate"%><br>
</ItemTemplate>
<HeaderTemplate>
ABC<br>
</HeaderTemplate>
</asp:Repeater>


Hi sswalia,
I used the method from above.
At the moment I have:

<itemtemplate>
<tr class="DatNieuws">
<%# DataBinder.Eval(Container.DataItem,"datum","{0:dd/MM/yyyy}")%>
</tr>
<tr class="Nieuws">
<img src=".\images\icon_news.gif" align="left"> <a
href='<%#(DataBinder.Eval(Container.DataItem,"type")=="N")?DataBinder.Eval
(Container.DataItem,"nieuwsid"):"wcharts"%>.aspx'>
<%# DataBinder.Eval(Container.DataItem,"titel")%></a>
</tr>
</itemtemplate>


It works. But is this also possible to add another condition?
In C# it's something like that (I let the DataBinder things in the swith
statement in C# to compare with the ASP.NET things):

switch (DataBinder.Eval(Container.DataItem,"type"))
{
case "N": DataBinder.Eval(Container.DataItem,"nieuwsid").aspx;
break;
case "C":
wcharts.aspx;
break;
case "P":
javascript:if(window.open('./poll.aspx','nieuwvenster','width=300,height=250
,status=no,toobar=no,menubar=no,scrollbars=no')) ;
break;
default: DataBinder.Eval(Container.DataItem,"nieuwsid").aspx;
break;
}


Thanx in advance !!!!!!
grz

Bernie V
 
B

Bernie V

Bernie V said:
"SSW" <[email protected]> schreef in bericht
news:[email protected]...

I found a solution.
This is how I did it:

<a
href="<%#(DataBinder.Eval(Container.DataItem,"type").ToString()=="N")?DataBi
nder.Eval(Container.DataItem,"nieuwsid")+".aspx":(DataBinder.Eval(Container.
DataItem,"type").ToString()=="C")?"wcharts.aspx":"javascript:if(window.open(
'./poll.aspx','nieuwvenster','width=300,height=250,status=no,toobar=no,menub
ar=no,scrollbars=no'))"%>">

Thx to everyone !


grz

Bernie V
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top