471,066 Members | 1,247 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,066 software developers and data experts.

asp:repeater control

I am using asp:repeater control. I would like to create a conditional row <tr> when the data in
DataBinder.Eval(Container.DataItem, "Activity") returns '1'.
I need something like this: <%if( Convert.ToString(DataBinder.Eval(Container.DataIte m, "Activity")) == "1") { %>...<%}%>
My attempts putting 'DataBinder.Eval(Container.DataItem, "Activity")' in 'if' statement were not successfull.
It seems like 'DataBinder.Eval(Container.DataItem, "Activity") ' works only with '#' perprocessor.
How do I put my bound data in 'Repeater' control inside if statement?
Thanks for your help,
Oleg

Nov 18 '05 #1
3 1972
Hi,

this kind of conditional processing is good to do in ItemDataBound event
(which is raised for every row bound to data source) and from there impact
what is outputted to the column. Another option is use a helper function
(more about it here: http://www.aspalliance.com/31 )

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

"Oleg" <an*******@discussions.microsoft.com> wrote in message
news:B6**********************************@microsof t.com...
I am using asp:repeater control. I would like to create a conditional row
<tr> when the data in
DataBinder.Eval(Container.DataItem, "Activity") returns '1'.
I need something like this: <%if(
Convert.ToString(DataBinder.Eval(Container.DataIte m, "Activity")) == "1")
{ %>...<%}%>
My attempts putting 'DataBinder.Eval(Container.DataItem, "Activity")' in
'if' statement were not successfull.
It seems like 'DataBinder.Eval(Container.DataItem, "Activity") ' works only
with '#' perprocessor.
How do I put my bound data in 'Repeater' control inside if statement?
Thanks for your help,
Oleg
Nov 18 '05 #2
<%# %> functions like <%= %> so you would need to do something like this to make it work without OnItemDataBoun

<%# ( Convert.ToString(DataBinder.Eval(Container.DataIte m, "Activity")) == "1") ?"<tr><td>Activity: "+Convert.ToString(DataBinder.Eval(Container.DataI tem, "Activity"))+"</td></tr>":"" %

You need to make use of the ?: operator for this...

To help you understand how it works here's a simple exampl

If(someControl.Visible

someLiteral.Text = "some control is visible"

els

someLiteral.Text = "some control is not visible"
This same code could be written like this using the ?: operato

someLiteral.Text = someControl.Visible?"some control is visible":"some control is not visible"

the part before the ? is the condition, the part after the ? is what is returned if the condition is true and the part after the : is what is returned if the condition is fals

obviously since <%# %> is much like <%= %> you can not have code statements between the tags, just string values so you must make use of the conditional ?: operator to make it work... just like you can't write someLiteral.Text = if(...) "some control is visible" else "some control is not visible".

although this might be a nasty way of doing things, i guess the proper way would be to handle things like this in OnItemDataBound event handler, sometimes it is simpler to do it this way and you have the advantage of keeping your HTML in ascx/aspx instead of cs which means you don't have to recompile when you make changes to your HTML..

hope this helps..

----- Oleg wrote: ----

I am using asp:repeater control. I would like to create a conditional row <tr> when the data in
DataBinder.Eval(Container.DataItem, "Activity") returns '1'.
I need something like this: <%if( Convert.ToString(DataBinder.Eval(Container.DataIte m, "Activity")) == "1") { %>...<%}%
My attempts putting 'DataBinder.Eval(Container.DataItem, "Activity")' in 'if' statement were not successfull.
It seems like 'DataBinder.Eval(Container.DataItem, "Activity") ' works only with '#' perprocessor
How do I put my bound data in 'Repeater' control inside if statement
Thanks for your help
Ole

Nov 18 '05 #3
Thank you Adrijan.
I implemented the second part, without OnItemDataBound and it works fine
I thought about using OnItemDataBound also, but don't see any way to render html back on page
Oleg
Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Joe Fawcett | last post: by
5 posts views Thread by Scott Lyon | last post: by
3 posts views Thread by John Giblin | last post: by
3 posts views Thread by Kelly Leahy | last post: by
3 posts views Thread by Joe Fawcett | last post: by
1 post views Thread by Fred Dag | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.