如何在ASP.NET控件声明中向属性添加换行符?

时间:2009-04-09 17:35:58

标签: c# asp.net vb.net

我有一个sql数据源,我有一个很长的SQL字符串。我想在我的sql中添加换行符,但Visual Studio似乎不喜欢换行符。我怎么会换行?

实施例

<asp:SqlDataSource ID="SqlDataSource1" runat="server"         
        ProviderName="System.Data.SqlClient" 
        SelectCommand="select aci.ACIOI, aci.AccountNum, (select count(r.OI) from Report r where aci.ACIOI = r.ACIOI) as ReportCount, ci.Name, aci.BusinessName, ci.[Address] As StreetAddress, ci.Town, ci.Zip, ci.Phone  from AdditionalCustomerInformation aci  left join CustomerInformation ci on ci.ACI_OI = aci.ACIOI where (select count(r.OI) from Report r where aci.ACIOI = r.ACIOI) >= 1" 
        >        
        </asp:SqlDataSource>

2 个答案:

答案 0 :(得分:3)

这对我来说很好:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ProviderName="System.Data.SqlClient" SelectCommand="select aci.ACIOI, 
aci.AccountNum, (select count(r.OI) from Report r where aci.ACIOI = r.ACIOI) as ReportCount,
ci.Name, aci.BusinessName, 
ci.[Address] As StreetAddress, ci.Town, 
ci.Zip, ci.Phone 
from AdditionalCustomerInformation aci left join CustomerInformation ci on ci.ACI_OI = aci.ACIOI 
where (select count(r.OI) from Report r where aci.ACIOI = r.ACIOI) >=1"> </asp:SqlDataSource>

......这是合乎逻辑的。只要整个SQL语句包含在SelectCommand属性的引号中,编译器就不应该关心你的标记是否被分解为单独的行。

出现的问题是由于SQL语句中的>符号。有两种方法可以转义该符号。您可以简单地使用&gt; HTML实体,如下所示:

SelectCommand = "SELECT.... &gt;= 1"

答案 1 :(得分:1)

HTML转义是必需的。替换你的&gt;与&amp; gt;

同样,&lt;变成&amp; lt;