asp:repeater control

G

Guest

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.DataItem, "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
 
T

Teemu Keiski

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

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.DataItem, "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
 
G

Guest

<%# %> functions like <%= %> so you would need to do something like this to make it work without OnItemDataBoun

<%# ( Convert.ToString(DataBinder.Eval(Container.DataItem, "Activity")) == "1") ?"<tr><td>Activity: "+Convert.ToString(DataBinder.Eval(Container.DataItem, "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.DataItem, "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
 
G

Guest

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
 

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,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top