Hi kankon,
In DataList OnItemDataBound event update the NavigateUrl property to open the url in new tab.
Please refer below sample.
HTML
<form id="form1" runat="server">
<div>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
<asp:DataList ID="dlCustomers" runat="server" CellSpacing="0" RepeatLayout="Table" RepeatColumns="2" OnItemDataBound="OnItemDataBound">
<ItemTemplate>
<table class="table">
<tr>
<th colspan="2">Id
</th>
</tr>
<tr>
<td>
<asp:Label ID="lblId" Text='<%# Eval("Id") %>' runat="server" /></td>
</tr>
<tr>
<td>
<asp:HyperLink ID="lnkLink" runat="server" NavigateUrl='<%# Eval("Link") %>'
ImageUrl="~/imagefolder/Koala.jpg" ImageWidth="35" ImageHeight="35"></asp:HyperLink>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</div>
</form>
Namespaces
C#
using System.Data;
VB.Net
Imports System.Data
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[2] { new DataColumn("Id"), new DataColumn("Link") });
dt.Rows.Add(1, "https://www.aspforums.net/");
dt.Rows.Add(2, "https://www.aspsnippets.com/");
dlCustomers.DataSource = dt;
dlCustomers.DataBind();
}
}
protected void OnItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
HyperLink hlLink = e.Item.FindControl("lnkLink") as HyperLink;
hlLink.NavigateUrl = "javascript:void(window.open('" + hlLink.NavigateUrl + "','_blank', 'width=300,height=200,left=100,top=100,resizable=yes'));";
}
}
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 DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn(1) {New DataColumn("Id"), New DataColumn("Link")})
dt.Rows.Add(1, "https://www.aspforums.net/")
dt.Rows.Add(2, "https://www.aspsnippets.com/")
dlCustomers.DataSource = dt
dlCustomers.DataBind()
End If
End Sub
Protected Sub OnItemDataBound(ByVal sender As Object, ByVal e As DataListItemEventArgs)
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
Dim hlLink As HyperLink = TryCast(e.Item.FindControl("lnkLink"), HyperLink)
hlLink.NavigateUrl = "javascript:void(window.open('" & hlLink.NavigateUrl & "','_blank', 'width=300,height=200,left=100,top=100,resizable=yes'));"
End If
End Sub
Screenshot