我做了一个论坛,其中论坛的帖子显示是用TextBox,<asp:textbox id="postContentText" cssclass="content" Runat="server" TextMode="MultiLine" Text="<%# DataBinder.Eval(Container.DataItem, "TopicContent") %>" ></asp:textbox>我想把用户发的帖子中的如: http://www.sina.com/postNew.asp?ID=122 等自动加上超链接(现在很多论坛都有这个功能),请问该如何办?
解决方案 »
- 业务层能放sql语句不???
- asp.net网站程序发布到IIS后, 浏览出现错误
- asp.net 2005怎样在服务器端验证表单
- 我如何给用户在服务器上分配一定大小的空间和域名?
- 在SQL中,存储字段的类型为MONEY型,读取时怎么不让其四舍五入?
- 在datagrid中放datalist,怎么填充datalist啊?
- 请教一个有关"ASP.NET"服务器问题?
- 自定义报表?难啊!
- 请问如何安装iewebcontrols?
- 请教:痕迹保留的思路
- 有关于人事管理方面的软件吗?
- 在同一个虚拟目录下得两个应用程序,用户登陆一个程序后,在另一个程序中,如何得登陆人员得session["usercode"]
str=my.Replace(str,@"<A HREF=""$2"" TARGET=_blank>$2</A>"); my=new Regex(@"(\[URL\])(.[^\[]*)(\[\/URL\])",RegexOptions.IgnoreCase);
str=my.Replace(str,@"<A HREF=""http://$2"" TARGET=_blank>$2</A>"); my=new Regex(@"(\[URL=(http:\/\/.[^\[]*)\])(.[^\[]*)(\[\/URL\])",RegexOptions.IgnoreCase);
str=my.Replace(str,@"<A HREF=""$2"" TARGET=_blank>$3</A>");
my=new Regex(@"(\[URL=(.[^\[]*)\])(.[^\[]*)(\[\/URL\])",RegexOptions.IgnoreCase);
str=my.Replace(str,@"<A HREF=""http://$2"" TARGET=_blank>$3</A>"); my=new Regex(@"(\[EMAIL\])(\S+\@.[^\[]*)(\[\/EMAIL\])",RegexOptions.IgnoreCase);
str=my.Replace(str,@"<A HREF=""mailto:$2"">$2</A>"); my=new Regex(@"(\[EMAIL=(\S+\@.[^\[]*)\])(.[^\[]*)(\[\/EMAIL\])",RegexOptions.IgnoreCase);
str=my.Replace(str,@"<A HREF=""mailto:$2"" TARGET=_blank>$3</A>"); my=new Regex(@"^(HTTP://[A-Za-z0-9\./=\?%\-&_~`@':+!]+)",RegexOptions.IgnoreCase);
str=my.Replace(str,@"<a target=_blank href=$1>$1</a>"); my=new Regex(@"(HTTP://[A-Za-z0-9\./=\?%\-&_~`@':+!]+)$",RegexOptions.IgnoreCase);
str=my.Replace(str,@"<a target=_blank href=$1>$1</a>");
我是这样用的, Content是原来的帖子内容,newContent是转换后的帖子,发现还是没有变化:
在.aspx中:<asp:textbox id="postContentText" cssclass="content" Runat="server" TextMode="MultiLine" Text="<%# ProcessLink(DataBinder.Eval(Container.DataItem, WebTutorial.Common.Data.ForumPostData.CONTENT_FIELD)) %>" ForeColor="#636060"></asp:textbox>在后台代码中: public string ProcessLink(object Content)
{
string strContent = Content.ToString();
Regex my= new Regex(@"(\[URL\])(http:\/\/.[^\[]*)(\[\/URL\])",RegexOptions.IgnoreCase);
strContent=my.Replace(strContent,@"<A HREF=""$2"" TARGET=_blank>$2</A>"); my=new Regex(@"(\[URL\])(.[^\[]*)(\[\/URL\])",RegexOptions.IgnoreCase);
strContent=my.Replace(strContent,@"<A HREF=""http://$2"" TARGET=_blank>$2</A>"); my=new Regex(@"(\[URL=(http:\/\/.[^\[]*)\])(.[^\[]*)(\[\/URL\])",RegexOptions.IgnoreCase);
strContent=my.Replace(strContent,@"<A HREF=""$2"" TARGET=_blank>$3</A>");
my=new Regex(@"(\[URL=(.[^\[]*)\])(.[^\[]*)(\[\/URL\])",RegexOptions.IgnoreCase);
strContent=my.Replace(strContent,@"<A HREF=""http://$2"" TARGET=_blank>$3</A>"); my=new Regex(@"(\[EMAIL\])(\S+\@.[^\[]*)(\[\/EMAIL\])",RegexOptions.IgnoreCase);
strContent=my.Replace(strContent,@"<A HREF=""mailto:$2"">$2</A>"); my=new Regex(@"(\[EMAIL=(\S+\@.[^\[]*)\])(.[^\[]*)(\[\/EMAIL\])",RegexOptions.IgnoreCase);
strContent=my.Replace(strContent,@"<A HREF=""mailto:$2"" TARGET=_blank>$3</A>"); my=new Regex(@"^(HTTP://[A-Za-z0-9\./=\?%\-&_~`@':+!]+)",RegexOptions.IgnoreCase);
strContent=my.Replace(strContent,@"<a target=_blank href=$1>$1</a>"); my=new Regex(@"(HTTP://[A-Za-z0-9\./=\?%\-&_~`@':+!]+)$",RegexOptions.IgnoreCase);
strContent=my.Replace(strContent,@"<a target=_blank href=$1>$1</a>");
string newContent = strContent;
return newContent;
}