请问给文字自动带上网址连接,这是怎么做到的啊?? 我发现有的新闻文章中,好多词组带上连接,可以连接到其他网址上,想请教一下,这是如何实现的??我想不至于在添加新闻时一个个的添加上去的吧,应该是在程序中设定好的吧 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 数据库里的关键词和网址一一对应,前台replace一下关键词private string getHTML(DataTable keysUrls,string content){ for(int i=0;i<keysUrls.Rows.Count;i++){ content = content.Replace(keysUrls.Rows[i]["Key"],"<a alt="+keysUrls.Rows[i]["Key"]+" href="+keysUrls.Rows[i]["Url"]+">"+keysUrls.Rows[i]["Key"]+"</a>")}} 少了return,手写的,大致应该就这么处理吧,正则也可行。 aspx: <asp:Repeater ID="Repeater1" runat="server" > <HeaderTemplate> <table class="STYLE2" border="0" cellpadding="1" cellspacing="1" style="border-right:#CC6600 thin dotted; border-top:#CC6600 thin dotted; border-left:#CC6600 thin dotted; width: 480px; border-bottom:#CC6600 thin dotted; background-color: #333333; color: #ffffff; text-decoration: none;"> <tr> <th bgcolor="#CC6600" style="width:40px ;">编号</th><th bgcolor="#CC66OO" style="width:150px">歌名</th><th bgcolor="#CC6600" style="width:30px">试听</th><th bgcolor="#CC6600" style="width:60px">点击率</th> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td bgcolor="#666666"> <asp:Label runat="server" ID="LblSongID" Text='<%# Eval("SongID") %>' /> </td> <td bgcolor="#666666"> <asp:Label runat="server" ID="LblSongName" Text='<%# Eval("SongName") %>' /> </td> <td bgcolor="#666666" style="width:30px;"> <a href="sound.html" target="_blank" ><img src="images/play.gif" border="0" alt="点击试听"/></a> </td> <td bgcolor="#666666"> <asp:Label runat="server" ID="LblSongStat" Text='<%# Eval("SongStat") %>' /> </td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater>cs:protected void Page_Load(object sender, EventArgs e){ SqlDataSource SongDataSource = new SqlDataSource(); SongDataSource.ConnectionString = SqlHelper.ConnectionStringLocalTransaction; SongDataSource.DataSourceMode = SqlDataSourceMode.DataSet; SongDataSource.SelectCommandType = SqlDataSourceCommandType.Text; SongDataSource.SelectCommand = "Select * FROM [80NT] where ID =下拉列表选择的文本 orDER BY [ID]"; this.Repeater1.DataSource = SongDataSource; this.Repeater1.DataBind();} 在着个reapter的离子里面,在label控件的外面你加上<a href='default.aspx?id=<%Eval("id")%>'></a>这样就可以实现类似新闻的连接 http://topic.csdn.net/u/20091028/13/df7cd47d-0f30-4361-9695-a6aa547b8d7a.html button 宽度 顶者有份,每年的第一周怎么计算,以及每年有多少周怎么计算 如何通过Javascript给ActiveX控件的属性赋值 请问怎样用正则表达式获得图片路径及其属性? 奇怪的DropDownList问题 ajax updatepanel局部刷新问题 急急! 请教一个LINQ语句 知道.net安全证书或公匙私匙加密解密的进来帮帮忙? 为什么fill错了,我应该怎么解决? 怎么让做出的网页里没有菜单栏,工具栏,地址栏? 求。给文章关键字加链接函数。非常复杂。 麻烦高手给修改下这段代码 ie8下控制固定gridview表头正常显示
前台replace一下关键词
private string getHTML(DataTable keysUrls,string content)
{
for(int i=0;i<keysUrls.Rows.Count;i++)
{
content = content.Replace(keysUrls.Rows[i]["Key"],"<a alt="+keysUrls.Rows[i]["Key"]+" href="+keysUrls.Rows[i]["Url"]+">"+keysUrls.Rows[i]["Key"]+"</a>")
}
}
aspx:
<asp:Repeater ID="Repeater1" runat="server" >
<HeaderTemplate>
<table class="STYLE2" border="0" cellpadding="1" cellspacing="1" style="border-right:#CC6600 thin dotted; border-top:#CC6600 thin dotted;
border-left:#CC6600 thin dotted; width: 480px; border-bottom:#CC6600 thin dotted;
background-color: #333333; color: #ffffff; text-decoration: none;">
<tr>
<th bgcolor="#CC6600" style="width:40px ;">编号</th><th bgcolor="#CC66OO" style="width:150px">歌名</th><th bgcolor="#CC6600" style="width:30px">试听</th><th bgcolor="#CC6600" style="width:60px">点击率</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td bgcolor="#666666">
<asp:Label runat="server" ID="LblSongID" Text='<%# Eval("SongID") %>' />
</td>
<td bgcolor="#666666">
<asp:Label runat="server" ID="LblSongName" Text='<%# Eval("SongName") %>' />
</td>
<td bgcolor="#666666" style="width:30px;">
<a href="sound.html" target="_blank" ><img src="images/play.gif" border="0" alt="点击试听"/></a> </td>
<td bgcolor="#666666">
<asp:Label runat="server" ID="LblSongStat" Text='<%# Eval("SongStat") %>' />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>cs:
protected void Page_Load(object sender, EventArgs e)
{
SqlDataSource SongDataSource = new SqlDataSource();
SongDataSource.ConnectionString = SqlHelper.ConnectionStringLocalTransaction;
SongDataSource.DataSourceMode = SqlDataSourceMode.DataSet;
SongDataSource.SelectCommandType = SqlDataSourceCommandType.Text;
SongDataSource.SelectCommand = "Select * FROM [80NT] where ID =下拉列表选择的文本 orDER BY [ID]";
this.Repeater1.DataSource = SongDataSource;
this.Repeater1.DataBind();
} 在着个reapter的离子里面,在label控件的外面你加上<a href='default.aspx?id=<%Eval("id")%>'></a>
这样就可以实现类似新闻的连接