列表视图空值
如果字段为空,我不希望显示标签。在我的数据库行中,所有列的数据并不完整。
我认为这会起作用:
<% if(# Eval("recipe_by") == null){%><br /><br /><%} else {%>Recipe by:
<br /><br /> <asp:Label ID="recipe_byLabel" Font-Bold="True" runat="server" Text='<%# Eval("recipe_by") %>' /> }
我收到此错误:
编译器错误消息:CS1040: 预处理器指令必须显示为 第一个非空白字符 一行
来源错误:
第 386 行:第 387 行:第 387 行 388:<% if(# Eval("recipe_by") == null){%>
<%} else {%>配方 作者:第 389 行:
' />第 390 行:编译器错误消息:CS1040: 预处理器指令必须显示为 第一个非空白字符 一行
来源错误:
第 386 行:第 387 行:第 387 行 388:<% if(# Eval("recipe_by") == null){%>
<%} else {%>配方 作者:第 389 行:
' />第 390 行:
I don't want the label to show if the field is null. In my database rows, data isn't complete for all columns.
I thought this would work:
<% if(# Eval("recipe_by") == null){%><br /><br /><%} else {%>Recipe by:
<br /><br /> <asp:Label ID="recipe_byLabel" Font-Bold="True" runat="server" Text='<%# Eval("recipe_by") %>' /> }
I get this error:
Compiler Error Message: CS1040:
Preprocessor directives must appear as
the first non-whitespace character on
a lineSource Error:
Line 386: Line 387: Line
388:<% if(# Eval("recipe_by") ==
null){%><%} else {%>Recipe
by: Line 389:' /> } Line 390:
Compiler Error Message: CS1040:
Preprocessor directives must appear as
the first non-whitespace character on
a lineSource Error:
Line 386: Line 387: Line
388:<% if(# Eval("recipe_by") ==
null){%><%} else {%>Recipe
by: Line 389:' /> } Line 390:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这是哈希字符 (#),我们在 blighty 中称之为 - 我很确定您不希望它出现在那里。它用于预处理器指令。
It's the hash character (#), as we call it in blighty - I'm pretty sure you don't want that there. That's used for Preprocessor Directives.
这里是
Here it is
我发誓一定能做到!
I could've swore that would do it!
如果您厌倦了尝试调整内联标记以使其正常工作,您可以使用其他两种方法:
后面代码是我最喜欢的 - 如果您正在操作像 gridview 等对象.,您可能必须使用 onrowdatabound 或其他类似事件来设置可见属性。
如果您必须使用内联标记,有时,也许在您的 SQL 语句中拥有一个“可见”列会更容易 - 即:
然后在您的内联代码中:
If you get tired of trying to tweak the inline tags to work right, you could use two other approaches:
Code behind is my favorite -- if you're operating on an object like a gridview, etc., you might have to use the onrowdatabound or other similar event to set visible properties.
If you must use inline tags, sometimes, maybe it would be easier just to have a "visible" column in your SQL Statement -- i.e.:
And then in your inline code:
这就是我最终使用的,,,效果很好!
This is what I ended up using,,, works GREAT!!