求教高人--如何在ASP.NET网页中显示从数据库数据格式如换行等
我最近用编写一个新闻中心网站,我用GRIDVIEW控件用HYPERLINK方式在一个网页中显示NEWS的TITLE, 用另一个网页显示NEWS的BODY部分,用的是DETAILSVIEW控件,通过点击第一个网页中的NEWS的TITLE超链接,接可以在另一个网页中显示NEWS的内容部分即BODY部分了。以上的做法我都会,也没问题。我的问题是: 从数据库调出的BODY部分,是一整段显示的,没换行,没CSS。我搜素了一下,网上也没好的转换格式,恳请高手帮忙。
附上我的网页编码:
1. 显示TITLE:
Page Title="Beijington News Headline" Language="C#" MasterPageFile="~/MasterPages/Main.master" AutoEventWireup="true" CodeFile="NewsHeadline.aspx.cs" Inherits="Management_NewsHeadline" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" runat="server" contentplaceholderid="cpContent">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="Id" DataSourceID="SqlDataSource1" GridLines="None"
ShowHeader="False">
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="Id"
DataNavigateUrlFormatString="NewsDisplay.aspx?Id={0}" DataTextField="Title"
HeaderText="Title" Target="_blank" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:BeijingtonConnectionString %>"
SelectCommand="SELECT [Id], [Title] FROM [News]"></asp:SqlDataSource>
</asp:Content>
2. 显示内容:BODY
Page Title="Beijington News Display" Language="C#" MasterPageFile="~/MasterPages/Main.master" AutoEventWireup="true" CodeFile="NewsDisplay.aspx.cs" Inherits="Management_NewsDisplay" %>
<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>
<%@ Register src="../Controls/Comments.ascx" tagname="Comments" tagprefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" runat="server" contentplaceholderid="cpContent">
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataSourceID="SqlDataSource1" GridLines="None" Height="300px"
HorizontalAlign="Left" Width="700px" AllowPaging="True">
<Fields>
<asp:TemplateField HeaderText="Body" ShowHeader="False" SortExpression="Body">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Body") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Body") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Body") %>'></asp:Label>
</ItemTemplate>
<ItemStyle VerticalAlign="Top" />
</asp:TemplateField>
</Fields>
</asp:DetailsView>
<br />
<span />
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:BeijingtonConnectionString %>"
SelectCommand="SELECT [Body] FROM [News] WHERE ([Id] = @Id)">
<SelectParameters>
<asp:QueryStringParameter Name="Id" QueryStringField="Id" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<script type="text/javascript">
$(document).ready(function () {
$('#MainContent').css('background-color', 'blue');
});
</script>
</asp:Content>
等待高人指点。
谢谢!