我自己用C#写的论坛里出现这样一个问题:别人回复贴子的内容不能分段落,是一整篇。效果如下:
办公办公室而我想要的形式是:
办公
办公室我知道用str.Replace(System.Environment.NewLine, " <br> ");
可是我具体不会用,不知道这个代码放到什么地方。
谁能帮我下呀,我的QQ78238036可以远程,谢谢!
办公办公室而我想要的形式是:
办公
办公室我知道用str.Replace(System.Environment.NewLine, " <br> ");
可是我具体不会用,不知道这个代码放到什么地方。
谁能帮我下呀,我的QQ78238036可以远程,谢谢!
解决方案 »
- 为什么我一个项目里面的网页有的可以打开有的就打不开?
- C# 后台获取前台jQuery的JSON数据为什么无法读出来?
- 关于php与aso.net相结合的问题!!!
- 编程加密web.config
- LinkButton的 Visible="<%# IsAdmin %>" 设置不启作用?
- 查询重复的问题 哪位高手看看啊
- 安装ie web controls时遇到的问题
- 网址内容规划中,www.zgso.com,大家说加什么栏目好
- encodeURIComponent 编码 cs 后台写法
- 关于uploadify上传多图片的问题,求各大神帮帮忙~!
- 请问 文本框验证用户存在问题 用的TEXTCHANGE
- gridview绑定
我问的是这样的代码放在哪里,写入数据库时还是读出数据库时?怎么写?
<br />是换行(如果你给文本容器设置了宽度,文本会自动换行的)
那么读出数据库时具体代码怎么写呀?我的原程序是:
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();
我试了后不行呀出现错误了:
编译错误
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。 编译器错误信息: 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>
<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>