I’m binding my DataRepeater control to a table that has many columns. I’d like to only display a subset of those, depending on what is populated.
How/where should I do my contitional tests within a dataRepeater? This is the code within my itemtemplate:
<% if (0= (DataBinder.Eval(Container.DataItem, "first").ToString().Length))
{
i++;
}
%>
The error I get is: CS0103: The name ‘Container’ does not exist in the current context
You should be fine with this:
But depending on what you want to do, I would probably write a function to handle the binding of the data in order to retain separation between display and business logic.
e.g.
in your aspx:
in your code-behind:
personally, I prefer to do things this way rather than doing any logic inside the ASP. I know that it might seem a bit silly to some people, but I like to keep my business logic separate from my display logic whereever possible.