Is it possible to use if condition inside repeater control on asp.net webform?
I need to show PercentEngineeringDesign field value if ScopeTypeID = 2 otherwise show empty field.
I am getting error on true part (second parameter).
<td><%# If(DataBinder.Eval(Container.DataItem, "ScopeTypeID").ToString() = "2", <%#DataBinder.Eval(Container.DataItem, "PercentEngineeringDesign")%>, "")%> </td>
I don't think you can cent the <%
tags like that. Try just:
<td><%# If(DataBinder.Eval(Container.DataItem, "ScopeTypeID").ToString() = "2", DataBinder.Eval(Container.DataItem, "PercentEngineeringDesign"), "")%> </td>
Or better yet, do that logic in your model instead of in the markup .
you can create other property in your class and do all work there then just display result in repeater just like this:
public int ID { get;set;};
public int Code {get { // Do Your if condition here }}
then display code as statue of ID
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.