473,811 Members | 3,220 Online
Bytes | Software Development & Data Engineering Community
+ 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="rptWebDocLi st" runat="server">
<HeaderTemplate >
<table border="1">
</HeaderTemplate>
<ItemTemplate >

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

<tr><td width="280" colspan="3"><hr color=#0000FF></td></tr>
<tr>
<td width="120"><%# Container.DataI tem("Status") %></div></td>
<td width="80"><%# Container.DataI tem("StatusCoun t") %></div></td>
<td width="80"><%# Container.DataI tem("PercentTot al") %>%</div></td>
</tr>

<% Else %>

<tr>
<td width="120"><%# Container.DataI tem("Status") %></div></td>
<td width="80"><%# Container.DataI tem("StatusCoun t") %></div></td>
<td width="80"><%# Container.DataI tem("PercentTot al") %>%</div></td>
</tr>

<% End If %>

</ItemTemplate>
<FooterTemplate >
</table>
</FooterTemplate>
</asp:Repeater></div></td>
--
Thanks in advance,
sck10
Nov 18 '05 #1
3 19817
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="rptWebDocLi st" runat="server">
<HeaderTemplate >
<table border="1">
</HeaderTemplate>
<ItemTemplate >

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

<tr><td width="280" colspan="3"><hr color=#0000FF></td></tr>
<tr>
<td width="120"><%# Container.DataI tem("Status") %></div></td>
<td width="80"><%# Container.DataI tem("StatusCoun t") %></div></td>
<td width="80"><%# Container.DataI tem("PercentTot al") %>%</div></td>
</tr>

<% Else %>

<tr>
<td width="120"><%# Container.DataI tem("Status") %></div></td>
<td width="80"><%# Container.DataI tem("StatusCoun t") %></div></td>
<td width="80"><%# Container.DataI tem("PercentTot al") %>%</div></td>
</tr>

<% End If %>

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

--

Scott Mitchell
mi******@4guysf romrolla.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.DataI tem("Status") ) %>

<tr>
<td width="120"><%# Container.DataI tem("Status") %></div></td>
<td width="80"><%# Container.DataI tem("StatusCoun t") %></div></td>
<td width="80"><%# Container.DataI tem("PercentTot al") %>%</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(strin g 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
1101
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( 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,...
2
3304
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 reference not set to an instance of an object". This error message commonly occurs when a server control is incorrecly declared, so naturally I have double checked this. To test this, I moved the aspx code for the DataGrid ('myNestedDataGrid')...
3
2068
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( 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,...
1
3471
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 selectedindexchanged eventhandler for radiobuttonlist in itemdatabound,but cannot figure out which items dropdownlist in
1
2728
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 contains various pieces of information inside a custom object, including an id field.
1
2937
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. I have tried to set the button's visibility in Page_Load (after data binding), but I get a NullReferenceException stating that "Object reference not set to an instance of an object".
4
1469
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 layout: Accounts John Smith 12/12/2003 Mary Watson 04/05/2001 Training
1
2393
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 available on the code behind file for a click event. After the SQL command has run, I'd like to post back to another page. When I set the PostBackURL property, it posts back before the insert is performed. Can I either:
1
5660
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='<%# DataBinder.Eval(Container.DataItem, "DELIVERY") %>' runat="server"/> <% else %> <asp:Label Text='<%# DataBinder.Eval(Container.DataItem, "DELIVERY") %>' runat="server"/>
0
10651
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10392
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
10403
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
10136
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9208
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...
1
7671
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5555
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
5693
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3020
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.