468,107 Members | 1,312 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,107 developers. It's quick & easy.

using a condition in a repeater control

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,"nieuw sid")%>.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,"nieuw sid")%>.aspx'>
<%# DataBinder.Eval(Container.DataItem,"titel")%>
</a>
</tr>
</itemtemplate>
<footertemplate>
</table>
</footertemplate>
</asp:repeater>
thx in advance !
grz

Bernie V

--
http://www.djberniev.be
Nov 18 '05 #1
4 7635
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.

Bernie V wrote:
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,"nieuw sid")%>.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,"nieuw sid")%>.aspx'>
<%# DataBinder.Eval(Container.DataItem,"titel")%>
</a>
</tr>
</itemtemplate>
<footertemplate>
</table>
</footertemplate>
</asp:repeater>
thx in advance !
grz

Bernie V

Nov 18 '05 #2
SSW
Yes u can do it.

Replace Below
<img src=".\images\icon_news.gif" align="left"> <a
href='<%#DataBinder.Eval(Container.DataItem,"nieuw sid")%>.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")%>.as px'>
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
"Bernie V" <bernd.vantyghem@pandoradotbe> wrote in message
news:OB*************@TK2MSFTNGP11.phx.gbl...
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,"nieuw sid")%>.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,"nieuw sid")%>.aspx'>
<%# DataBinder.Eval(Container.DataItem,"titel")%>
</a>
</tr>
</itemtemplate>
<footertemplate>
</table>
</footertemplate>
</asp:repeater>
thx in advance !
grz

Bernie V

--
http://www.djberniev.be

Nov 18 '05 #3
"SSW" <fr************@hotmail.com> schreef in bericht
news:ej**************@TK2MSFTNGP11.phx.gbl...
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").asp x;
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").asp x;
break;
}
Thanx in advance !!!!!!
grz

Bernie V


--
http://www.djberniev.be
Nov 18 '05 #4
"Bernie V" <bernd.vantyghem@pandoradotbe> schreef in bericht
news:uU**************@TK2MSFTNGP11.phx.gbl...
"SSW" <fr************@hotmail.com> schreef in bericht
news:ej**************@TK2MSFTNGP11.phx.gbl...


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,st atus=no,toobar=no,menub
ar=no,scrollbars=no'))"%>">

Thx to everyone !
grz

Bernie V
--
http://www.djberniev.be
Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Oleg | last post: by
reply views Thread by Peter Johansen | last post: by
1 post views Thread by olduncleamos | last post: by
1 post views Thread by rhungund | last post: by
1 post views Thread by Ganesh Muthuvelu | last post: by
reply views Thread by Christina | last post: by
1 post views Thread by =?Utf-8?B?R3V1czEyMw==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.