473,698 Members | 2,283 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Data Item, "Activity") returns '1'.
I need something like this: <%if( Convert.ToStrin g(DataBinder.Ev al(Container.Da taItem, "Activity") ) == "1") { %>...<%}%>
My attempts putting 'DataBinder.Eva l(Container.Dat aItem, "Activity") ' in 'if' statement were not successfull.
It seems like 'DataBinder.Eva l(Container.Dat aItem, "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 2063
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*******@disc ussions.microso ft.com> wrote in message
news:B6******** *************** ***********@mic rosoft.com...
I am using asp:repeater control. I would like to create a conditional row
<tr> when the data in
DataBinder.Eval (Container.Data Item, "Activity") returns '1'.
I need something like this: <%if(
Convert.ToStrin g(DataBinder.Ev al(Container.Da taItem, "Activity") ) == "1")
{ %>...<%}%>
My attempts putting 'DataBinder.Eva l(Container.Dat aItem, "Activity") ' in
'if' statement were not successfull.
It seems like 'DataBinder.Eva l(Container.Dat aItem, "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.ToStrin g(DataBinder.Ev al(Container.Da taItem, "Activity") ) == "1") ?"<tr><td>Activ ity: "+Convert.ToStr ing(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.Tex t = "some control is visible"

els

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

someLiteral.Tex t = someControl.Vis ible?"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.Tex t = 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.Data Item, "Activity") returns '1'.
I need something like this: <%if( Convert.ToStrin g(DataBinder.Ev al(Container.Da taItem, "Activity") ) == "1") { %>...<%}%
My attempts putting 'DataBinder.Eva l(Container.Dat aItem, "Activity") ' in 'if' statement were not successfull.
It seems like 'DataBinder.Eva l(Container.Dat aItem, "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
1597
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> <%# DataBinder.Eval(Container.DataItem, "Key") %> = <%# DataBinder.Eval(Container.DataItem, "Value") %> </ItemTemplate> </AlternatingItemTemplate> </asp:Repeater>
5
8264
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 source code. If you want me to post code, though, just say so. In a nutshell, I've got an ASP.NET application that has one main ASPX page. On that ASPX page, it has a user control (an ASCX) that displays the actual data and controls I need.
3
1904
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="<%# BasketLineDAO.GetByEventCategory(content.Id,10)%>" Runat=server> This does not work. I do not get any rows from the repeater. but when I assign the datasource and bind it in the behing code, I do get the rows
4
3644
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 Eric Gerbil 1 Eric Bird 10
3
2046
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. However, when the user clicks a save button (not in the asp:repeater, but on the form itself) I would like to (on postback) update the values in the database and redisplay the page. I can't figure out how to reference the controls generated by...
3
2536
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 Hashtable. Originally my code was: <asp:Repeater id="rptFamily" runat="server" DataSource="<%# family %>"> <ItemTemplate> <%# DataBinder.Eval(Container.DataItem, "Key") %> = <%# DataBinder.Eval(Container.DataItem, "Value") %>
1
4896
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 I try to give the repeater values by removing if (!IsPostBack) {} from the
1
17040
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 control in my aspx page with two image buttons, one for an edit command, another a delete command. Here is a cut down code fragment. ...
2
3876
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" /><br /> <label... <label... <label...
0
8676
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8608
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9029
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8898
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7734
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.