using a condition in a repeater control

  • Thread starter Thread starter Bernie V
  • Start date Start date
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
 
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.
 
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
 
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
 
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
 
Back
Top