If statements in repeater templates

  • Thread starter Thread starter Cappy
  • Start date Start date
C

Cappy

Hi.

I have a table row as follows in my repeater template

<tr>
<td class=error align=right>
-
</td>
<td class=error colspan=4>
<%# DataBinder.Eval(Container.DataItem, "Error") %>
</td>
</tr>

Is there anyway I can put an if statement around the row so it only
displays if the "Error" is of .length > 0

The only way I can think of doing it anyother way is using a lable
control and setting its value to be the html code above onItemDataBind
event of the repeater.

There must be a better way.

Cheers
Amit
 
Amit:

If the DataSource is a DataTable, you could attach a DataView and set
the RowFilter property so the control only sees the rows you need.

Another easy way would be to call a method in your code behind class
from within a data binding expression. In this case, you would not
have <tr> and <td> tags in your aspx, but write them out
programatically during data binding. Inside of the method you could
determine if you need to write the row out or not.

in aspx:

<%# DoLogic(Container.DataItem) %>

in aspx.cs:

public string DoLogic(object item)
{
...
}

HTH,
 
Back
Top