如何在源文件中声明条件 [英] How to declare if condition in source file
本文介绍了如何在源文件中声明条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何声明是否在源文件中
How to declare if in source file
<% if(Eval("img_url") != ""){%>
我正在这样使用,但显示错误
请任何人可以帮助我
在此先感谢
我可以这样声明吗?
I am using like this but it shown error
Please any one can help me
Thanks in advance
can i declare like this:
public string GetAppropriateHTML()
{
string html = "";
if (Eval("a_comment_counter") == "")
{
html = "<p style="font-size: .9em; text-align: right; color: #808080; border-bottom: 1px #d8d8d8 solid; padding-bottom: 10px"><i>0 comments</i>";
}
else
{
html = "<a href="a_comments.aspx?a_id=<%# Eval("a_id")%>"><%# Eval("a_comment_counter")%> comments</a>";
}
return html;
}
但不支持
but it not supported
推荐答案
您不能将if-else构造与Eval函数一起使用.
这是bcoz:
评估只能写在<%#%>中.而if-else不能写在那里.
另外,如果条件不能应用于Eval等.
应用条件 [
You cant use if-else construct with Eval function.
This is bcoz:
Eval can be written only in <%# %> whereas if-else cant be written there.
Also, if condition cant be applied to Eval etc.
Applying condition[^]
This link will be very careful and will definitely solve your problem.
您的示例不是cpomplete,或者您没有全部复制:
Your sample either isn''t cpomplete, or you just didn''t copy it all:
<% if(Eval("img_url") != ""){%>
some html goes here
<%} else {%>
some different html goes here
<%}%>
请注意最后的右括号.
我更喜欢在orer的代码中放置逻辑,以保持aspx文件尽可能的干净.
Notice the closing brace at the end.
I prefer to put logic in the code-behind in orer to keep the aspx file as clean as possible.
public string GetAppropriateHTML()
{
string html = "";
if (Eval("img_url") != "")
{
html = "some html goes here";
}
else
{
html = "some other html goes here"
}
return html;
}
这样可以将aspx文件中的混乱情况减少为:
Which reduces the clutter in the aspx file to this:
<%=GetAppropriateHTML() %>
这篇关于如何在源文件中声明条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文