Click here to Skip to main content
12,303,940 members (74,364 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#2.0 .NET3.0 C#3.0 .NET3.5 C# ASP , +
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>
           
 
          </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>
              
 
              <span style="color: White;"><%# this.Eval("NewsItemContent") %></span> 
              
              
 
              <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 12-Apr-11 5:41am
Edited 12-Apr-11 5:43am
v2

1 solution

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

Solution 1

First, why is it important to maintain line breaks?

Second,

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

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

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 | Mobile
Web02 | 2.8.160530.1 | Last Updated 12 Apr 2011
Copyright © CodeProject, 1999-2016
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