[英]how do I use the value resolved from a Data-Binding expression in an in-line if-else statement in Web Forms?
我从ASP.NET Web窗体ascx控件中的以下数据绑定表达式中获得了很好的字符串值:
<%# ((MyCompany.CoreLib.Main.ChallengeQuestion)Container.DataItem).AnswerType %>
我想做类似的事情:
<EditItemTemplate>
<% if (%>
<%# ((MyCompany.CoreLib.Main.ChallengeQuestion)Container.DataItem).AnswerType %>
<% == "DateTime") { %>
Show this text
<% ; } else { %>
Show this other text
<% ; } %>
<EditItemTemplate>
这样的事情可能吗?
这是不可能的,但是您可以在后面的代码中定义一个方法,并在aspx上使用它
后面的代码
public string GetAnswerTypeText(MyCompany.CoreLib.Main.ChallengeQuestion challengeQuestion)
{
if (challengeQuestion.AnswerType.Equals("DateTime"))
{
return "some text";
}
else
{
return "some other text";
}
}
ASPX
<%# GetAnswerTypeText((MyCompany.CoreLib.Main.ChallengeQuestion)Container.DataItem) %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.