asp.net(c#)读取数据问题!!!

来源:百度知道 编辑:UC知道 时间:2024/05/17 03:38:41
在数据库中建立的news表,有n_id(主键,自动增长),n_title(文章标题),n_content(正文,text类型的),三个字段.

我想在A页面中读取这些数据,
我原本的做法是用
conn = new SqlConnection("database = syj;user id = sa;pwd = sql;data source = (local)");
conn.Open();
string strsql = "select n_title from news where n_id = '"+ArticleID+"'";//参数已经传过来
SqlCommand cmd = new SqlCommand(strsql,conn);
string title=Convert.ToString(cmd.ExecuteScalar());
this.Label1.Text=title;

以上将标题读取的出来,且没有问题!!
接着我读取正文

string strsql2 = "select n_con from news where n_id = '"+ArticleID+"'";
SqlCommand cmd2 = new SqlCommand(strsql2,conn);
string con=Convert.ToString(cmd2.ExecuteScalar());
this.Label4.Text=con;

以上将正文读取出来,但是,正文只是被连续的读取出来了,

请问怎么样才能将正文有段落,有规则的输出在页面上呢!!!

很急,各位帮帮忙!!希望能给详细的代码,将我以前的代码全推翻也可以,只要能实现我的要求就可以!!
我会在追分的!!
拜托,请看清楚,我不是要分页,只是想有段落的整齐的将数据库中的正文显示在页面上!!!!

你是用的textbox输入的吧,存入数据库是无格式的,

输出时,要用 原文.replace("/n","<br>")
这是分段,
还有一些记不清了,

最好使用freetextbox,存入数据库里就是有格式的,

<ItemTemplate>
<a href='<%# DataBinder.Eval(Container.DataItem,"zsdatu")%>'><asp:Image ID="image1" ImageUrl='<%# Eval("zsdatu") %>' runat ="server" /></a>
</ItemTemplate>

分页嘛,我给你点资料,自己去改一下,我以前就是根据这个做的,
本文收藏在我博客裏了
http://hi.baidu.com/lancy/blog/item/12be3b29b6cec3fe99250ab9.html
DataGrid控件内部也使用了PagedDataSource类,PagedDataSource 类封装 DataGrid 控件的属性,这些属性使 DataGrid 可以执行分页。

PagedDataSource 类的部分公共属性:
AllowCustomPaging 获取或设置指示是否启用自定义分页的值。
AllowPaging 获取或设置指示是否启用分页的值。
Count 获取要从数据源使用的项数。
CurrentPageIndex 获取或设置当前页的索引。
DataSource 获