I'm using ASP.NET, and I'm trying to us an if statement for a container in a datarepeater. Here's an example of what I'm trying to do:
<%# if Container.dataitem("someField") = 1 then %>
do this...
<% else %>
do something else...
<% end if %>
But, of course, I'm getting errors that container isn't declared. I know that <%# container.dataitem("someField") %> will work, but I'm not sure how to use that in an if-then-else statement.Do it like this
In the HTML
<%# MyFunction(Databinder.Eval(Container.DataItem, "SomeField")) %>
in code
Public MyFunction (ByVal strValue As Type) As ReturnType
If strValue = 1 Then
Return SomeValue
Else
Return SomeOtherValue
End If
End FunctionI know that would work, but... The one part that I want to show is a table with bound data in the datarepeater. I guess I could always use a panel..
EDIT: Seems it didn't like me setting the panels visibility in the code-behind section (the panels were in the datagrid).Do it like this
In the HTML
<%# MyFunction(Databinder.Eval(Container.DataItem, "SomeField")) %>
in code
Public MyFunction (ByVal strValue As Type) As ReturnType
If strValue = 1 Then
Return SomeValue
Else
Return SomeOtherValue
End If
End Function
hi.
You can not returna server control
ex.
Public MyFunction (ByVal strValue As Type) As ReturnType
If strValue = 1 Then
Return "<asp:Button id='id' runat='server'"
what's the solution?
it should be render or...?
<%# if Container.dataitem("someField") = 1 then %>
do this...
<% else %>
do something else...
<% end if %>
But, of course, I'm getting errors that container isn't declared. I know that <%# container.dataitem("someField") %> will work, but I'm not sure how to use that in an if-then-else statement.Do it like this
In the HTML
<%# MyFunction(Databinder.Eval(Container.DataItem, "SomeField")) %>
in code
Public MyFunction (ByVal strValue As Type) As ReturnType
If strValue = 1 Then
Return SomeValue
Else
Return SomeOtherValue
End If
End FunctionI know that would work, but... The one part that I want to show is a table with bound data in the datarepeater. I guess I could always use a panel..
EDIT: Seems it didn't like me setting the panels visibility in the code-behind section (the panels were in the datagrid).Do it like this
In the HTML
<%# MyFunction(Databinder.Eval(Container.DataItem, "SomeField")) %>
in code
Public MyFunction (ByVal strValue As Type) As ReturnType
If strValue = 1 Then
Return SomeValue
Else
Return SomeOtherValue
End If
End Function
hi.
You can not returna server control
ex.
Public MyFunction (ByVal strValue As Type) As ReturnType
If strValue = 1 Then
Return "<asp:Button id='id' runat='server'"
what's the solution?
it should be render or...?