Click here to Skip to main content
13,255,340 members (51,088 online)
Rate this:
Please Sign up or sign in to 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" 
        SelectCommand="SELECT [NewsItemTitle], [NewsItemContent], [DT], [NewsItemLink] FROM [News] ORDER BY [DT] DESC">

  <asp:DataList ID = "listNews" runat = "server" DataSourceID = "srcNews" 
EnabViewState = "false">
           <span style="color: Orange; font-size: x-large; margin-removed 15px;">Latest news </span>
           <br />
            <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>

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 12-Apr-11 6:41am
Updated 12-Apr-11 6:43am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

First, why is it important to maintain line breaks?


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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171114.1 | Last Updated 12 Apr 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100