我发现有的新闻文章中,好多词组带上连接,可以连接到其他网址上,想请教一下,这是如何实现的??我想不至于在添加新闻时一个个的添加上去的吧,应该是在程序中设定好的吧

解决方案 »

  1.   

    数据库里的关键词和网址一一对应,
    前台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>")
    }
    }
      

  2.   

    少了return,手写的,大致应该就这么处理吧,正则也可行。
      

  3.   


    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>
    这样就可以实现类似新闻的连接
      

  4.   

    http://topic.csdn.net/u/20091028/13/df7cd47d-0f30-4361-9695-a6aa547b8d7a.html