[thelist] ASP.NET repeater conditions
noah
noah at tookish.net
Mon Nov 17 21:44:58 CST 2003
Hi,
I'm teaching myself ASP.NET (using C#) -- it's my first shot at an OO
language, so I'm struggling a bit.
I have a page that pulls data from a database and displays it using a
Repeater control. This works. Where I'm running into trouble is trying to
conditionally modify what shows up on the page based on what comes out of
the database. Here's what I have:
<asp:Repeater id="EventList" runat="server">
<ItemTemplate>
<h1><%# Convert.ToString(DataBinder.Eval(Container.DataItem, "title"))
%>: <%# Convert.ToString(DataBinder.Eval(Container.DataItem, "subtitle"))
%></h1>
The thing is that the "subtitle" doesn't necessarily exist (it can be NULL)
-- if it doesn't exist, what prints now is:
"Title: "
Obviously, this doesn't work -- what I need to do is test if "subtitle"
exists, and print "Title: Subtitle" if it does and just "Title" if it doesn't.
I'm pretty sure I could work this out using some old-fashioned procedural
code, but I'm trying to do this the right way :-).
I've found some examples describing how to do something similar with a
DataGrid, but I haven't been able to extrapolate this to work with a
Repeater. I'm pretty sure I need to use "OnItemDataBound," but the syntax
has me stumped.
Any help would be greatly appreciated.
Thanks,
Noah
More information about the thelist
mailing list