Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi guys!
I have two questions:

First: how to preserve all the line-breaks and whitespaces in SQL Server table.
I'm creating an .aspx page to display the latest news in some area.
    <asp:SqlDataSource ID = "srcNews" runat = "server" 
        ConnectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\TranceSiteDB.mdf;Integrated Security=True;User Instance=True" 
        ProviderName="System.Data.SqlClient" 
        SelectCommand="SELECT [NewsItemTitle], [NewsItemContent], [DT], [NewsItemLink] FROM [News] ORDER BY [DT] DESC">
 


  <asp:DataList ID = "listNews" runat = "server" DataSourceID = "srcNews" 
EnabViewState = "false">
          <HeaderTemplate>
           <span style="color: Orange; font-size: x-large; margin-removed 15px;">Latest news </span>
           <br />
          </HeaderTemplate>
           <itemtemplate>
           
            <div style="border: 1px solid white; removed: relative; padding: 5px 10px 0px 10px; margin-removed 15px; margin-removed 10px; margin-removed 10px;" önmouseover="this.className = 'hot_ITEM';" önmouseout="this.className = null;">
              <span style="color: Orange; font-size: larger;"><%# this.Eval("NewsItemTitle") %></span>
              <br />
              <span style="color: White;"><%# this.Eval("NewsItemContent") %></span> 
              
              <br />
              <span style="color: Lime;  font-weight: bolder; removed: absolute; removed 5px; removed auto; margin-removed 0px; margin-removed auto; removed 0;"><%# this.Eval("DT", "{0:d}") %></span>
              <a href="<%# Eval(" newsitemlink=") %>" style="margin-removed 5px;">Read More...</a>
            </div> 
           </itemtemplate>


I use asp:DataList control to bind to my SQL source:
My SQL Server table structure:
NewsItemID uniqueidentifier PRIMARY KEY NOT NULL DEFAULT NEWID( ),
NewsItemTitle nvarchar(500) NOT NULL,
NewsItemContent ntext NOT NULL,
DT datetime NOT NULL,
NewsItemLink nvarchar(500) NOT NULL


When I bind to the NewsItemContent column through
"pre" tag it shows me a LONG ---- VERY LONG!!! line of text...
How to save all the linebreaks when inserting data into SQL SERVER
(to insert data into SQL server I simply COPY/PASTE text files
and insert data into SQL table cell as one line)

Second question:
<a href="<%# Eval(" newsitemlink=") %>" style="margin-removed 5px;">Read More...</a> 


When I try to bind to the links column of a table I cannot bind to anchor link.. It's because of symbol " "
how to fix it???
Posted
Updated 12-Apr-11 5:43am
v2

1 solution

First, why is it important to maintain line breaks?

Second,

<a href='<%# Eval("NewItemLink") %>' style="margin-removed 5px;'>Read More...</a>
;

The Eval method is looking for the column name newsitemlink= which, according to your schema, doesn't exist. You should also use single quote rather than double to have the html parsed correctly.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900