我自己用C#写的论坛里出现这样一个问题:别人回复贴子的内容不能分段落,是一整篇。效果如下:
办公办公室而我想要的形式是:
办公
办公室我知道用str.Replace(System.Environment.NewLine, " <br> "); 
可是我具体不会用,不知道这个代码放到什么地方。
谁能帮我下呀,我的QQ78238036可以远程,谢谢!

解决方案 »

  1.   

    要说就具体点,别人发贴时候不会自己写\n\r,他们按enter回车键分开的段落。
    我问的是这样的代码放在哪里,写入数据库时还是读出数据库时?怎么写?
      

  2.   

    网页中用<p>就好了,首页缩进两个字的CSS p {text-indent:2em}
    <br />是换行(如果你给文本容器设置了宽度,文本会自动换行的)
      

  3.   


    那么读出数据库时具体代码怎么写呀?我的原程序是:
    OleDbConnection conn; 
    string strconn = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" + Server.MapPath(".\\App_Data\\shopbag.mdb");
            conn = new OleDbConnection(strconn);
            conn.Open();
    string strID = Request.QueryString["gid"];
            string SqlStr = "select reply_title,reply_content,reply_data,reply_ip,reply_name from [reply] where [reply_titleclass]=" + strID;
            SqlStr += " Union all select '',tiezi_content,tiezi_data,tiezi_ip,tiezi_name from [tiezi] where [titleclass]=" + strID;
            SqlStr += " order by [reply_data] ";
            OleDbDataAdapter da;
            OleDbCommand  cmd;
            DataSet ds = new DataSet();
            cmd = new OleDbCommand(SqlStr,conn);
            da = new OleDbDataAdapter(cmd);
            da.Fill(ds,"reply");
            this.Repeater1.DataSource=ds.Tables[0].DefaultView;
            this.Repeater1.DataBind(); 
            conn.Close();
      

  4.   

    string SqlStr = "select reply_title,ISNULL(reply_content, "暂无内容"),reply_data,reply_ip,reply_name from [reply] where [reply_titleclass]=" + strID;绑定时替换成相应的Web标记,<%# Eval("reply_content").ToString().Replace(@"\r\n", "<br />") %>
      

  5.   


    我试了后不行呀出现错误了:
    编译错误 
    说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。 编译器错误信息: CS0117: “object”并不包含“Replace”的定义源错误: 行 24: <td  bgColor="#F0F8FF" ><%# DataBinder.Eval(Container.DataItem,"reply_name") %>
    行 25: </td>
    行 26: <td  bgColor="#F0F8FF" ><%# DataBinder.Eval(Container.DataItem,"reply_content").Replace(@"\r\n", "<br />")  %>
    行 27: </td>
    行 28: </tr>
     
      

  6.   

    String.Replace(@"\r\n", "<br />")
      

  7.   

    Repeater项模板里的td内容你换用Literal控件试试,Mode设置成PassThrough<asp:Literal ID="Literal1" runat="server" Mode="PassThrough" Text='<%#Eval("Memo") %>'></asp:Literal>Mode共有三种方式:Encode、PassThrough、Transform
      

  8.   

    如果还不行的话,改用文本编辑器来存取数据吧,推荐xheditor,CSDN博客中的正是这个控件。
      

  9.   


        <script src="../Scripts/xheditor-1.1.9/jquery/jquery-1.4.2.min.js" type="text/javascript"></script>
        <script src="../Scripts/xheditor-1.1.9/xheditor_plugins/ubb.min.js" type="text/javascript"></script>
        <script src="../Scripts/xheditor-1.1.9/xheditor-1.1.9-zh-cn.min.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(function() {
                $('#tbtmpContent').xheditor({
                    upLinkUrl: "upload.aspx", upLinkExt: "zip,rar,txt",
                    upImgUrl: "upload.aspx", upImgExt: "jpg,jpeg,gif,png,bmp",
                    upFlashUrl: "upload.aspx", upFlashExt: "swf",
                    upMediaUrl: "upload.aspx", upMediaExt: "wmv,avi,wma,mp3,mid",
                    shortcuts: { 'ctrl+enter': submitForm }
                });
            });
            function submitForm() { $('#form1').submit(); }
        </script><asp:TextBox ID="tbtmpContent" TextMode="MultiLine" BorderWidth="0" runat="server"
                                        Width="100%" CssClass="inputc" Height="250px"></asp:TextBox>upload.aspx
    <%@ Page Language="C#" AutoEventWireup="true" CodePage="65001" %>
    <%@ Import namespace="System" %>
    <%@ Import namespace="System.Collections" %>
    <%@ Import namespace="System.Configuration" %>
    <%@ Import namespace="System.Data" %>
    <%@ Import namespace="System.Web" %>
    <%@ Import namespace="System.Web.Security" %>
    <%@ Import namespace="System.Web.UI" %>
    <%@ Import namespace="System.Web.UI.HtmlControls" %>
    <%@ Import namespace="System.Web.UI.WebControls" %>
    <%@ Import namespace="System.Web.UI.WebControls.WebParts" %><script runat="server">
        /*
     * upload demo for c# .net 2.0
     * 
     * @requires xhEditor
     * @author Jediwolf<[email protected]>
     * @licence LGPL(http://www.opensource.org/licenses/lgpl-license.php)
     * 
     * @Version: 0.1.3 (build 100504)
     * 
     * 注1:本程序仅为演示用,请您务必根据自己需求进行相应修改,或者重开发
     * 注2:本程序将HTML5上传与普通POST上传转换为byte类型统一处理
     * 
     */protected void Page_Load(object sender, EventArgs e)
    {
        Response.Charset = "UTF-8"; // 初始化一大堆变量
    string inputname = "filedata";//表单文件域name
        string attachdir ="../upload";     // 上传文件保存路径,结尾不要带/
        int dirtype = 1;                 // 1:按天存入目录 2:按月存入目录 3:按扩展名存目录  建议使用按天存
        int maxattachsize = 2097152;     // 最大上传大小,默认是2M
        string upext = "txt,rar,zip,jpg,jpeg,gif,png,swf,wmv,avi,wma,mp3,mid";    // 上传扩展名
        int msgtype = 2;                 //返回上传参数的格式:1,只返回url,2,返回参数数组
    string immediate = Request.QueryString["immediate"];//立即上传模式,仅为演示用
        byte[] file;                     // 统一转换为byte数组处理
        string localname = "";
        string disposition = Request.ServerVariables["HTTP_CONTENT_DISPOSITION"];    string err = "";
        string msg = "''";
        
        if (disposition != null)
        {
            // HTML5上传
            file = Request.BinaryRead(Request.TotalBytes);
            localname = Regex.Match(disposition, "filename=\"(.+?)\"").Groups[1].Value;// 读取原始文件名
        }
        else 
        {        
            HttpFileCollection filecollection = Request.Files;
            HttpPostedFile postedfile = filecollection.Get(inputname);        // 读取原始文件名
            localname = postedfile.FileName;
            // 初始化byte长度.
            file = new Byte[postedfile.ContentLength];
            
            // 转换为byte类型
            System.IO.Stream stream = postedfile.InputStream;
            stream.Read(file, 0, postedfile.ContentLength);
            stream.Close();        filecollection = null;
        }
        
        if (file.Length == 0)err = "无数据提交";
        else
        {
            if (file.Length > maxattachsize)err = "文件大小超过" + maxattachsize + "字节";
            else
            {
                string attach_dir, attach_subdir, filename, extension, target;            // 取上载文件后缀名
                extension = GetFileExt(localname);
                
                if (("," + upext + ",").IndexOf("," + extension + ",") < 0)err = "上传文件扩展名必需为:" + upext;
                else
                {
                    switch (dirtype)
                    {
                        case 2:
                            attach_subdir = "month_" + DateTime.Now.ToString("yyMM");
                            break;
                        case 3:
                            attach_subdir = "ext_" + extension;
                            break;
                        default:
                            attach_subdir = "day_" + DateTime.Now.ToString("yyMMdd");
                            break;
                    }
                    attach_dir = attachdir + "/" + attach_subdir + "/";                // 生成随机文件名
                    Random random = new Random(DateTime.Now.Millisecond);
                    filename = DateTime.Now.ToString("yyyyMMddhhmmss") + random.Next(10000) + "." + extension;                target = attach_dir + filename;
                    try
                    {
                        CreateFolder(Server.MapPath(attach_dir));                    System.IO.FileStream fs = new System.IO.FileStream(Server.MapPath(target), System.IO.FileMode.Create, System.IO.FileAccess.Write);
                        fs.Write(file, 0, file.Length);
                        fs.Flush();
                        fs.Close();
                    }
                    catch (Exception ex)
                    {
                        err = ex.Message.ToString();
                    }                // 立即模式判断
                    if (immediate == "1") target = "!" + target;
    target=jsonString(target);
    if(msgtype==1)msg = "'"+target+"'";
                    else msg = "{'url':'" + target + "','localname':'" + jsonString(localname) + "','id':'1'}";
                }
            }
        }    file = null;
        
        Response.Write("{'err':'" + jsonString(err) + "','msg':" + msg + "}");
    }
    string jsonString(string str) 
    {
        str = str.Replace("\\", "\\\\");
        str = str.Replace("/", "\\/");
        str = str.Replace("'", "\\'");
        return str;
    }
    string GetFileExt(string FullPath) 
    {
        if (FullPath != "")return FullPath.Substring(FullPath.LastIndexOf('.') + 1).ToLower();
        else return "";
    }void CreateFolder(string FolderPath)
    {
        if (!System.IO.Directory.Exists(FolderPath))System.IO.Directory.CreateDirectory(FolderPath);
    }
        
    </script>