在ASP.net页面条件逻辑 [英] Conditional Logic in ASP.net page

查看:110
本文介绍了在ASP.net页面条件逻辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些code打印出DATABSE值到一个asp.net页面上的中继器控制。然而,一些返回的值是空/空白 - 这使得其结果很难看的时候有空格。

I have some code that prints out databse values into a repeater control on an asp.net page. However, some of the values returned are null/blank - and this makes the result look ugly when there are blank spaces.

你是怎么做到在asp.net控制条件逻辑,即打印出一个值,如果存在的话,其他人只是去到下一个值。

How do you do conditional logic in asp.net controls i.e. print out a value if one exists, else just go to next value.

我还要补充 - 我想要的标记是有条件的也是,因为如果没有价值我不想
标记为

I should also add - that I want the markup to be conditional also, as if there is no value I dont want a
tag either.

下面是code的片段下面只是为了显示值的类型,我从我的数据库取回。 (这是常见的地址2 不要有一个价值可言)。

Here is a snippet of code below just to show the type of values I am getting back from my database. (It is common for Address 2 not to have a value at all).

<div id="results">
    <asp:Repeater ID="repeaterResults" runat="server">
        <ItemTemplate>
             Company:      <strong><%#Eval("CompanyName") %></strong><br />
             Contact Name: <strong><%#Eval("ContactName") %></strong><br />
             Address:      <strong><%#Eval("Address1")%></strong><br />                    
                           <strong><%#Eval("Address2")%></strong><br />..................

非常感谢

推荐答案

这将是pretty主观的这个,因为它完全取决于你想在哪里以及如何处理空/空值,实际上哪一个这两个的你正在处理的。

It's going to be a pretty subjective one this as it completely depends on where and how you like to handle null / blank values, and indeed which one of those two you are dealing with.

例如,有的喜欢在数据库级别处理空值,有的喜欢在业务逻辑层和其他code默认值,喜欢的用户界面来处理默认/空值 - 更不用说选项过多在两者之间。

For example, some like to handle nulls at the database level, some like to code default values in the business logic layer and others like to handle default / blank values at the UI - not to mention the plethora of options in between.

无论哪种方式,我个人的选择是确保你显示没有数据可用于该领域在UI层面,以避免混乱。在沿线的最坏的东西:

Either way my personal choice would be to make sure you display that no data was available for that field at the UI level to avoid confusion. At worst something along the lines of:

<strong><% If (Eval("Address2").Length > 0) Then %><%#Eval("Address2")%><% Else %>No data available for Address 2<% End If %></strong><br />

这样,至少在用户知道没有可用的数据,而不是不知道,如果出现了一些系统/管理错误。

That way at least the user knows that no data is available, rather than not knowing if there has been some system / administrative error.

希望有所帮助:)

这篇关于在ASP.net页面条件逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆