If statement in repeater control

M

medium.fisher

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
 
I

intrader

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
 
M

medium.fisher

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%>
 
G

Guest

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(Container.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
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top