473,473 Members | 2,098 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

If Then statement inside of repeater control

Hello,

I am trying to use an If Then statement inside of a repeater control.
However, I am getting the following error:
Expression expected.

Any help would be appreciated.

Thanks in advance,

sck10
<asp:Repeater id="rptWebDocList" runat="server">
<HeaderTemplate>
<table border="1">
</HeaderTemplate>
<ItemTemplate>

<%# If Container.DataItem("Status") = " Total Not Reworked" Then %>

<tr><td width="280" colspan="3"><hr color=#0000FF></td></tr>
<tr>
<td width="120"><%# Container.DataItem("Status") %></div></td>
<td width="80"><%# Container.DataItem("StatusCount") %></div></td>
<td width="80"><%# Container.DataItem("PercentTotal") %>%</div></td>
</tr>

<% Else %>

<tr>
<td width="120"><%# Container.DataItem("Status") %></div></td>
<td width="80"><%# Container.DataItem("StatusCount") %></div></td>
<td width="80"><%# Container.DataItem("PercentTotal") %>%</div></td>
</tr>

<% End If %>

</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater></div></td>
--
Thanks in advance,
sck10
Nov 18 '05 #1
3 19764
Rather than trying to put a conditional statement in the <ItemTemplate>,
instead call a function from the <ItemTemplate>, passing in the
databound values that determine and are part of the output.

In your code portion, create a function with the same name and takes in
the same inputs, and returns a string. The string returned will be what
is displayed in the <ItemTemplate>

This explanation may not be that clear, but the following FAQ should
help: http://tinyurl.com/6muyn

It shows how to have the output customized based on a single field, but
the helper function could have an If statement and return a much more
complex HTML string.

hth
sck10 wrote:
Hello,

I am trying to use an If Then statement inside of a repeater control.
However, I am getting the following error:
Expression expected.

Any help would be appreciated.

Thanks in advance,

sck10
<asp:Repeater id="rptWebDocList" runat="server">
<HeaderTemplate>
<table border="1">
</HeaderTemplate>
<ItemTemplate>

<%# If Container.DataItem("Status") = " Total Not Reworked" Then %>

<tr><td width="280" colspan="3"><hr color=#0000FF></td></tr>
<tr>
<td width="120"><%# Container.DataItem("Status") %></div></td>
<td width="80"><%# Container.DataItem("StatusCount") %></div></td>
<td width="80"><%# Container.DataItem("PercentTotal") %>%</div></td>
</tr>

<% Else %>

<tr>
<td width="120"><%# Container.DataItem("Status") %></div></td>
<td width="80"><%# Container.DataItem("StatusCount") %></div></td>
<td width="80"><%# Container.DataItem("PercentTotal") %>%</div></td>
</tr>

<% End If %>

</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater></div></td>

--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
Nov 18 '05 #2
Hi Sck10,

Thanks for your posting. As for the problem you mentioned, here are some of
my understandings:
1. The<% %> expression is only used in page(or UserControl, ascx) 's page
level template , but unable to be used in any asp.net web server control's
databinding template. We can only use <%# %> databinding expression to
bind value to asp.net server control's properties or template. For example:
<asp:TextBox ... Text="<% ...%>" ...> is not allowed,

we should use <asp:TextBox ... Text=<%# .. %> ..>
Also, the expression or code will be called when the TextBox (or its parent
container )'s DataBind method is called.

2. As for your problem, I think you should put the If ...else statement
logic into the <#% %> block . Forexample:

<ItemTemplate>

<%# GetHeader( Container.DataItem("Status") ) %>

<tr>
<td width="120"><%# Container.DataItem("Status") %></div></td>
<td width="80"><%# Container.DataItem("StatusCount") %></div></td>
<td width="80"><%# Container.DataItem("PercentTotal") %>%</div></td>
</tr>
</ItemTemplate>

GetHeader( string) is a helper function defined in the codebehind class
which return the correct html depend on the input param. such as:

#must be protected or public so that we can call it in aspx page's inline
code
protected string GetHeader(string status)
{
if(status== xxx)
{
return "<tr><td width=\"280\" colspan=\"3\"><hr
color=#0000FF></td></tr>";
}else
{
return string.Empty;
}
}
Hope helps. IF you have anything else unclear, please feel free to post
here. Thanks.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #3
Hi Sck10,

Have you had a chance to check the suggestions in my last reply or have you
got any further ideas on this issue? If there're anything else we can help,
please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Oleg | last post by:
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(...
2
by: Stephen Miller | last post by:
I am using the OnItemDataBound event of Repeater control to nest a DataGrid within the Repeater. When I attempt to bind to the DataGrid using the DataSource method I get the error message "Object...
3
by: Oleg | last post by:
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(...
1
by: Ravi | last post by:
Hi, I have a radio button list and a dropdownlist inside a repeater control. Want to hide or display the dropdownlist based on selection in radiobuttonlist. I can add the...
1
by: Dot net work | last post by:
Hello. I have an interesting data binding scenario: I have a repeater control. It repeats a typical custom web user control. I also have a collection object, and each collection element...
1
by: Keith Harris | last post by:
Hi, I have a Repeater control which is bound to a dataset. In the footer of the repeater control, I have a Button whose visibility I want to vary according to the sum of a column being > 0. ...
4
by: medium.fisher | last post by:
Is there a way to do the following: My repeater data source has 3 fields. Department, Employee, and StartDate, and is sorted by Department. I want to use the repeater to get the following...
1
by: Annyka | last post by:
I've got a button inside a Repeater control Item Template I'm doing a SQL insert using a SqlDataSource Control based on the RepeaterName_ItemCommand event, since the button in the template isn't...
1
by: =?Utf-8?B?T2xlZw==?= | last post by:
using .net 2.0 Trying to put condition on current value in repeater in this manner: <% if(<%# DataBinder.Eval(Container.DataItem, "FROM_NET") != "Hourly Rate")%%> <asp:TextBox Value='<%#...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.