473,229 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,229 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 2038
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Joe Fawcett | last post by:
I'm having a problem binding an asp:repeater control to a Hashtable. Originally my code was: <asp:Repeater id="rptFamily" runat="server" DataSource="<%# family %>"> <ItemTemplate> <%#...
5
by: Scott Lyon | last post by:
I am having a strange problem. The program is a bit complex, but I'll try to simplify what I can. I apologize if this is complicated, but I think this would still be simpler than posting a bunch of...
3
by: John Giblin | last post by:
I have an asp repeater control which I am trying to assign the datasorce to it inline. Here is my code. <asp:Repeater ID="AddOnList" DataSource="<%#...
4
by: Eric | last post by:
Hello, I have the following dataset that I want to bind to a repeater to be displayed as a table. Owner Animal Volume --------------------------- Eric Dog 6 Eric Cat ...
3
by: Kelly Leahy | last post by:
I'm using an Asp:Repeater control with a text box in the item templates. This is for a system that has a number of items that the user can edit and I'd like to generate them based on a list. ...
3
by: Joe Fawcett | last post by:
Sorry about the multi post, I thought I'd sent to both groups simultaneously but somehow it failed to find this one the first time. I'm having a problem binding an asp:repeater control to a...
1
by: Fred Dag | last post by:
As far as I can work out when using the OnTextChanged event I cannot get the TextBox and Labels values when the event fires as they are populated by a <asp:repeater and so don't have values. If...
1
by: Timbo | last post by:
Hi all, This is my first message here so i'll try and include all the information that will help you help me out, if possible. Basically I am using C# in ASP.NET 2.0 and have a Repeater...
2
by: bissatch | last post by:
Hi, I am trying to output a list of checkboxes. Using ASP .NET controls, I was able to create the following: <label for="colour_red">Red: </label><asp:CheckBox ID="colour_red" runat="server"...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.