473,396 Members | 1,921 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,396 software developers and data experts.

If statement in repeater control

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
Sue Jones 11/10/2004

etc.

I have an idea of how the code would look:

strDepartment = "" 'somewhere in page load

<itemTemplate>

If datasource("Department") <> strTemplate Then
<tr>
<td colspan="2">output the department field</td>
</tr>
strDepartment = datasource("Department")
End If

output the Name and startdate in a tr td etc

The problem is I cannot find a way to refer to the datasource
department field to compare against the strDepartment.

Any ideas.

Thanks

Nov 19 '05 #1
4 1453
On Fri, 14 Oct 2005 10:03:17 -0700, me***********@uku.co.uk wrote:
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
Sue Jones 11/10/2004

etc.

I have an idea of how the code would look:

strDepartment = "" 'somewhere in page load

<itemTemplate>

If datasource("Department") <> strTemplate Then
<tr>
<td colspan="2">output the department field</td>
</tr>
strDepartment = datasource("Department")
End If

output the Name and startdate in a tr td etc

The problem is I cannot find a way to refer to the datasource
department field to compare against the strDepartment.

Any ideas.

Thanks

It is perfectly OK to use inline coding in your page's language; that is
use <% if ... %>. It is also OK to use the databinding syntax which has
limited expression capabilities, but you can call codebehind methods to
accomplish what you want.
Hint:The <%# DataBinder.Eval(Container.DataItem,
"Department") %> displays the current department
Nov 19 '05 #2
do you have the exact syntax to include the DataBinder in an if
statement. I have tried both of the below but they both give the
message Expression expected.

<%If <%# DataBinder.Eval(Container.DataItem,"Department") %> =
"Accounts" Then%>
<%End If%>

<%# If DataBinder.Eval(Container.DataItem,"Department") = "Accounts"
Then%>
<%End If%>

Nov 19 '05 #3
I believe, the syntax '<%# if ' would result a run time error

Another solution is simply hiding the TR in HTML

<tr style='<%#CheckDeptDisplay(DataBinder.Eval(Contain er.DataItem,
"Department").ToString())%>' >
<td colspan="2">output the department field</td>
</tr>

in Code behind

protected string CheckDeptDisplay(string Deptval)
{
if(Deptval=="INVENTORY")
return("display:"); //this will show the TR

return("display:none"); //this will hide the TR
}

"me***********@uku.co.uk" wrote:
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
Sue Jones 11/10/2004

etc.

I have an idea of how the code would look:

strDepartment = "" 'somewhere in page load

<itemTemplate>

If datasource("Department") <> strTemplate Then
<tr>
<td colspan="2">output the department field</td>
</tr>
strDepartment = datasource("Department")
End If

output the Name and startdate in a tr td etc

The problem is I cannot find a way to refer to the datasource
department field to compare against the strDepartment.

Any ideas.

Thanks

Nov 19 '05 #4
Thanks, that works fine.

Nov 19 '05 #5

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

Similar topics

8
by: Invalidlastname | last post by:
Hi, We are developing an asp.net application, and we dynamically created certain literal controls to represent some read-only text for certain editable controls. However, recently we found an issue...
3
by: sck10 | last post by:
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...
4
by: nicholas | last post by:
Got an asp.net data-repeater on my page. I can view the texts from the database (ex.: <%# Databinder.Eval(Container.DataItem, "contentEN") %> ), but I also would like to see the image, but only if...
1
by: olduncleamos | last post by:
Hello all, I am experimenting with the repeater control and ran into something that I wasn't expecting. I would appreciate if the experts can confirm or correct my understanding. Here is a...
7
by: charliewest | last post by:
Hello - I'm using a Repeater control to render information in a very customized grid-like table. The Repeater control is binded to a DataSet with several records of information. Within the...
8
by: fernandezr | last post by:
I would like to use a user control as a template inside a repeater. Some of the fields in the control should be hidden depending on whether or not there is data. I'm still a ASP .Net newbie so the...
4
by: Brad Baker | last post by:
I'm going a little crazy :) I'm trying to bind a repeater control to a dataset on page load using the following code: if (Request.QueryString != null) { string customerid = Request.QueryString;...
7
by: | last post by:
I have what's probably a simple page lifecycle question related to dynamically evaluating values that are placed by a repeater and dynmically placing user controls that use those values. I'm...
5
by: Brad Baker | last post by:
I am trying to make a "tabbed" interface by iterating through a dataset with a conditional statement. For example: ...
12
by: =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post by:
I'm doing a web app in VB/Dot Net 2.0. I'm probably a bit rusty and I have no experience using the repeater control. I have a user control I've created with multiple properties. I've created a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
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...
0
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...
0
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,...

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.