列表视图空值

发布于 2024-09-12 04:12:33 字数 822 浏览 3 评论 0原文

如果字段为空,我不希望显示标签。在我的数据库行中,所有列的数据并不完整。

我认为这会起作用:

 <% 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 line

Source 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 line

Source Error:

Line 386: Line 387: Line
388:<% if(# Eval("recipe_by") ==
null){%>

<%} else {%>Recipe
by: Line 389:

' /> } Line 390:

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

掩耳倾听 2024-09-19 04:12:33

这是哈希字符 (#),我们在 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.

回忆躺在深渊里 2024-09-19 04:12:33

这里是

<span>  
 <%# (Eval("recipe_by")==null)? "<br/><br/>":"Recipe By:<br/><br/>" %></span>  
    <asp:Label ID="recipe_byLabel" Font-Bold="True" runat="server" Text='<%# Eval("recipe_by") %>' />  

Here it is

<span>  
 <%# (Eval("recipe_by")==null)? "<br/><br/>":"Recipe By:<br/><br/>" %></span>  
    <asp:Label ID="recipe_byLabel" Font-Bold="True" runat="server" Text='<%# Eval("recipe_by") %>' />  
甜柠檬 2024-09-19 04:12:33
Compiler Error Message: CS0029: Cannot implicitly convert type 'string' to 'bool'

Source Error:



Line 388:         
Line 389:
Line 390:<asp:Label ID="recipe_byLabel" Font-Bold="True" Text="Recipe by:" runat="server"  
Line 391: Visible='<%# (Convert.ToString(Eval("recipe_by")))? Boolean.Parse("false"):Boolean.Parse("true") %>'></asp:Label>  
Line 392: 

我发誓一定能做到!

Compiler Error Message: CS0029: Cannot implicitly convert type 'string' to 'bool'

Source Error:



Line 388:         
Line 389:
Line 390:<asp:Label ID="recipe_byLabel" Font-Bold="True" Text="Recipe by:" runat="server"  
Line 391: Visible='<%# (Convert.ToString(Eval("recipe_by")))? Boolean.Parse("false"):Boolean.Parse("true") %>'></asp:Label>  
Line 392: 

I could've swore that would do it!

是伱的 2024-09-19 04:12:33

如果您厌倦了尝试调整内联标记以使其正常工作,您可以使用其他两种方法:

  • 后面的代码
  • 存储过程/sql 语句返回

后面代码是我最喜欢的 - 如果您正在操作像 gridview 等对象.,您可能必须使用 onrowdatabound 或其他类似事件来设置可见属性。

如果您必须使用内联标记,有时,也许在您的 SQL 语句中拥有一个“可见”列会更容易 - 即:

SELECT
   field1,
   field2,
   CASE WHEN recipe_by is null, 'false' ELSE 'true' END as recipe_by_visible
FROM
   table

然后在您的内联代码中:

...
visible = <% eval("recipe_by_visible") %>
...

If you get tired of trying to tweak the inline tags to work right, you could use two other approaches:

  • code behind
  • stored procedure / sql statement return

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.:

SELECT
   field1,
   field2,
   CASE WHEN recipe_by is null, 'false' ELSE 'true' END as recipe_by_visible
FROM
   table

And then in your inline code:

...
visible = <% eval("recipe_by_visible") %>
...
扎心 2024-09-19 04:12:33

这就是我最终使用的,,,效果很好!

<span><%# (String.IsNullOrEmpty(Convert.ToString(Eval("yield"))))? "":" <br/><br/>Yield:<br/><br/>" %></span>  
<asp:Label ID="yieldLabel" Font-Bold="True" runat="server" Text='<%# Eval("yield") %>' />  

This is what I ended up using,,, works GREAT!!

<span><%# (String.IsNullOrEmpty(Convert.ToString(Eval("yield"))))? "":" <br/><br/>Yield:<br/><br/>" %></span>  
<asp:Label ID="yieldLabel" Font-Bold="True" runat="server" Text='<%# Eval("yield") %>' />  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文