ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Display link (Url) on Web Page on ASP.Net DataList LinkButton Click using C# and VB.Net<p>Hi <a class="username" rel="indradeo"> indradeo</a>,</p> <p>Refer below sample.</p> <div style="line-height: normal; margin: 0in 0in 8pt;"><font size="2"><font face="Arial"><strong><u>Database</u></strong></font></font></div> <div style="line-height: normal; margin: 0in 0in 8pt;"><font size="2"><font face="Arial">This article makes use of a table named <u>Files</u> whose schema is defined as follows.</font></font></div> <p><img src="https://www.aspsnippets.com/Handlers/DownloadFile.ashx?File=95ae118b-8c5c-47e1-abca-22d926d22a5c.png" alt="Upload and Display Images using Path stored in database in GridView in ASP.Net using C# and VB.Net" /></p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;asp:DataList ID=&#34;DataList1&#34; runat=&#34;server&#34;&gt; &nbsp;&nbsp;&nbsp; &lt;ItemTemplate&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:LinkButton Text=&#39;&lt;%# Eval(&#34;Path&#34;) %&gt;&#39; runat=&#34;server&#34; OnClick=&#34;OpenFrame&#34; /&gt; &nbsp;&nbsp;&nbsp; &lt;/ItemTemplate&gt; &lt;/asp:DataList&gt; &lt;br /&gt; &lt;asp:Literal ID=&#34;ltEmbed&#34; runat=&#34;server&#34; /&gt;</pre> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Data; using System.Data.SqlClient; using System.Configuration;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Data.SqlClient Imports System.Data </pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { &nbsp;&nbsp;&nbsp; if (!this.IsPostBack) &nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using (SqlConnection con = new SqlConnection(constr)) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using (SqlCommand cmd = new SqlCommand("SELECT TOP 4 Id, Name, Path from tblfilespath", con)) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using (SqlDataAdapter da = new SqlDataAdapter(cmd)) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataTable dt = new DataTable(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; da.Fill(dt); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataList1.DataSource = dt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataList1.DataBind(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; } } protected void OpenFrame(object sender, EventArgs e) { &nbsp;&nbsp;&nbsp; LinkButton lnk = (sender) as LinkButton; &nbsp;&nbsp;&nbsp; string embed = "&lt;object data=\"{0}\" type=\"application/pdf\" width=\"500px\" height=\"300px\"&gt;"; &nbsp;&nbsp;&nbsp; embed += "If you are unable to view file, you can download from &lt;a href = \"{0}\"&gt;here&lt;/a&gt;"; &nbsp;&nbsp;&nbsp; embed += " or download &lt;a target = \"_blank\" href = \"http://get.adobe.com/reader/\"&gt;Adobe PDF Reader&lt;/a&gt; to view the file."; &nbsp;&nbsp;&nbsp; embed += "&lt;/object&gt;"; &nbsp;&nbsp;&nbsp; ltEmbed.Text = string.Format(embed, lnk.Text); }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load &nbsp;&nbsp;&nbsp; If Not Me.IsPostBack Then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Using con As SqlConnection = New SqlConnection(constr) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Using cmd As SqlCommand = New SqlCommand("SELECT Id, Name, Path from tblfilespath", con) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Using da As SqlDataAdapter = New SqlDataAdapter(cmd) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim dt As DataTable = New DataTable() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; da.Fill(dt) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataList1.DataSource = dt &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataList1.DataBind() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Using &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Using &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Using &nbsp;&nbsp;&nbsp; End If End Sub Protected Sub OpenFrame(ByVal sender As Object, ByVal e As EventArgs) &nbsp;&nbsp;&nbsp; Dim lnk As LinkButton = TryCast((sender), LinkButton) &nbsp;&nbsp;&nbsp; Dim embed As String = "&lt;object data=""{0}"" type=""application/pdf"" width=""500px"" height=""300px""&gt;" &nbsp;&nbsp;&nbsp; embed += "If you are unable to view file, you can download from &lt;a href = ""{0}""&gt;here&lt;/a&gt;" &nbsp;&nbsp;&nbsp; embed += " or download &lt;a target = ""_blank"" href = ""http://get.adobe.com/reader/""&gt;Adobe PDF Reader&lt;/a&gt; to view the file." &nbsp;&nbsp;&nbsp; embed += "&lt;/object&gt;" &nbsp;&nbsp;&nbsp; ltEmbed.Text = String.Format(embed, lnk.Text) End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://i.imgur.com/KWlMTKW.gif" alt="" width="426" height="452" /></p>https://www.aspforums.net:443/Threads/179747/Display-link-Url-on-Web-Page-on-ASPNet-DataList-LinkButton-Click-using-C-and-VBNet/https://www.aspforums.net:443/Threads/179747/Display-link-Url-on-Web-Page-on-ASPNet-DataList-LinkButton-Click-using-C-and-VBNet/Thu, 18 Jul 2019 06:35:49 GMT