Hi nauna,
Check this example. Now please take its reference and correct your code.
HTML
<asp:ListView ID="lvDetails" runat="server">
<ItemTemplate>
<div style="float: left; border: 1px solid #ccc;">
<%# Eval("Id") %>
</div>
<div style="border: 1px solid #ccc;">
<asp:Label ID="lblText" Text='<%# ConvertTextUrlToLink(Eval("Text").ToString()) %>'
runat="server" />
</div>
<br />
</ItemTemplate>
</asp:ListView>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.AddRange(new System.Data.DataColumn[] {
new System.Data.DataColumn("Id", typeof(int)),
new System.Data.DataColumn("Text", typeof(string)) });
dt.Rows.Add(1, "this is some link https://i.imgur.com/8z1737Y.gif");
dt.Rows.Add(2, "this is some link http://i.imgur.com/qR7DWZX.gif");
lvDetails.DataSource = dt;
lvDetails.DataBind();
}
}
public string ConvertTextUrlToLink(string url)
{
string str = @"((www\.|(http|https)+\:\/\/)[_.a-z0-9-]+\.[a-z0-9\/_:@=.+?,##%&~-]*[^.|\'|\# |!|\(|?|,| |>|<|;|\)])";
Regex regex = new Regex(str, RegexOptions.IgnoreCase);
return regex.Replace(url, "<a href=\"$1\" target=\"_blank\">$1</a>").Replace("href=\"www", "href=\"https://www");
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As System.Data.DataTable = New System.Data.DataTable()
dt.Columns.AddRange(New System.Data.DataColumn() {New System.Data.DataColumn("Id", GetType(Integer)), New System.Data.DataColumn("Text", GetType(String))})
dt.Rows.Add(1, "this is some link https://i.imgur.com/8z1737Y.gif")
dt.Rows.Add(2, "this is some link http://i.imgur.com/qR7DWZX.gif")
lvDetails.DataSource = dt
lvDetails.DataBind()
End If
End Sub
Public Function ConvertTextUrlToLink(ByVal url As String) As String
Dim str As String = "((www\.|(http|https)+\:\/\/)[_.a-z0-9-]+\.[a-z0-9\/_:@=.+?,##%&~-]*[^.|\'|\# |!|\(|?|,| |>|<|;|\)])"
Dim regex As Regex = New Regex(str, RegexOptions.IgnoreCase)
Return regex.Replace(url, "<a href=""$1"" target=""_blank"">$1</a>").Replace("href=""www", "href=""https://www")
End Function
Screenshot