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