Tutorial :How do I add linebreaks to a property in an ASP.NET control declaration?



Question:

I have a sql data source and I have a really long string of SQL. I want to put linebreaks in my sql but Visual Studio doesn't seem to like the linebreaks. How would I put in line breaks?

Example

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


Solution:1

This compiles just fine for me:

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

... which is logical. The compiler should not care if your markup is broken up into separate lines as long as the entire SQL statement is enclosed in quotes of the SelectCommand property.

The problem it appears is because of the > symbol in your SQL statement. There are two ways to escape that symbol. You could simply use the &gt; HTML entity instead, as follows:

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


Solution:2

HTML escaping is required. Replace your > with &gt;

Likewise, < becomes &lt;


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »