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.Get Anchor tag HREF (Text) on jQuery DataTable row click in ASP.Net<p>Hi <a class="username" rel="jovceka"> jovceka</a>,</p> <p>Refer below sample.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;html xmlns=&#34;http://www.w3.org/1999/xhtml&#34;&gt; &lt;head runat=&#34;server&#34;&gt; &lt;title&gt;&lt;/title&gt; &lt;link rel=&#34;stylesheet&#34; href=&#34;https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css&#34; /&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;https://code.jquery.com/jquery-1.11.1.min.js&#34;&gt;&lt;/script&gt; &lt;link rel=&#34;stylesheet&#34; type=&#34;text/css&#34; href=&#34;https://cdn.datatables.net/1.10.7/css/jquery.dataTables.min.css&#34; /&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;https://cdn.datatables.net/1.10.7/js/jquery.dataTables.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34;&gt; $(document).ready(function () { $.ajax({ url: &#39;&lt;%= Page.ResolveUrl(&#34;~/WebService.asmx/GetFiles&#34;)%&gt;&#39;, method: &#39;post&#39;, dataType: &#39;json&#39;, success: function (data) { $(&#39;#datatable&#39;).dataTable({ paging: true, sort: true, pageLength: 3, searching: true, data: data, columns: [ { &#39;data&#39;: &#39;Id&#39; }, { &#39;data&#39;: &#39;Name&#39; }, { &#39;data&#39;: &#39;link&#39;, &#39;render&#39;: function (data, type, row, meta) { return &#39;&lt;a id=&#34;lnk&#34; class=&#34;btn btn-info&#34; role=&#34;button&#34; href=&#34;&#39; + &#34;/&#34; + row.Link + &#39;&#34; target=&#34;_blank&#34;&gt;click &lt;/a&gt;&#39; } } ] }); }, error: function (response) { alert(response.responseText); } }); $(&#39;body&#39;).on(&#39;click&#39;, &#39;[id*=lnk]&#39;, function () { var data = $(this).parents(&#39;tr&#39;).find(&#39;td&#39;); var name = data.eq(1).html() var link = $(data.eq(2)).find(&#39;a&#39;).attr(&#39;href&#39;); $(&#39;[id*=TxtedtStrnameedit]&#39;).val(name); $(&#39;[id*=TxtedtStrLinkedit]&#39;).val(link); return false; }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form id=&#34;form1&#34; runat=&#34;server&#34;&gt; Name : &lt;input type=&#34;text&#34; id=&#34;TxtedtStrnameedit&#34; /&gt;&lt;br /&gt; Link : &lt;input type=&#34;text&#34; id=&#34;TxtedtStrLinkedit&#34; /&gt; &lt;div style=&#34;width: 100%; border: 1px solid black; padding: 3px&#34;&gt; &lt;table id=&#34;datatable&#34;&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;Id&lt;/th&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;Image&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tfoot&gt; &lt;tr&gt; &lt;th&gt;Id&lt;/th&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;Image&lt;/th&gt; &lt;/tr&gt; &lt;/tfoot&gt; &lt;/table&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt;</pre> <p><span style="text-decoration: underline;"><strong>WebService</strong></span></p> <p><span style="text-decoration: underline;"><strong>C#</strong></span></p> <pre class="brush: csharp">using System; using System.Collections.Generic; using System.Web.Services; using System.Web.Script.Serialization; using System.Data.SqlClient; using System.Data; using System.Configuration; /// &lt;summary&gt; /// Summary description for WebService /// &lt;/summary&gt; [WebService(Namespace = &#34;http://tempuri.org/&#34;)] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. [System.Web.Script.Services.ScriptService] public class WebService : System.Web.Services.WebService { public class File { public int Id { get; set; } public string Name { get; set; } public string Link { get; set; } } [WebMethod] public void GetFiles() { string cs = ConfigurationManager.ConnectionStrings[&#34;constr&#34;].ConnectionString; List&lt;File&gt; files = new List&lt;File&gt;(); using (SqlConnection con = new SqlConnection(cs)) { SqlCommand cmd = new SqlCommand(&#34;SELECT id,Name,path FROM tblFilesPath&#34;, con); cmd.CommandType = CommandType.Text; con.Open(); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { File file = new File(); file.Id = Convert.ToInt32(rdr[&#34;id&#34;]); file.Name = rdr[&#34;Name&#34;].ToString(); file.Link = rdr[&#34;path&#34;].ToString(); files.Add(file); } } JavaScriptSerializer js = new JavaScriptSerializer(); Context.Response.Write(js.Serialize(files)); } } </pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Web Imports System.Collections.Generic Imports System.Configuration Imports System.Data Imports System.Data.SqlClient Imports System.Web.Script.Serialization Imports System.Web.Services Imports System.Web.Services.Protocols &#39; To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. &lt;System.Web.Script.Services.ScriptService()&gt; _ &lt;WebService(Namespace:=&#34;http://tempuri.org/&#34;)&gt; _ &lt;WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)&gt; _ &lt;Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()&gt; _ Public Class WebService Inherits System.Web.Services.WebService Public Class File Public Property Id As Integer Public Property Name As String Public Property Link As String End Class &lt;WebMethod()&gt; _ Public Sub GetFiles() Dim cs As String = ConfigurationManager.ConnectionStrings(&#34;constr&#34;).ConnectionString Dim files As List(Of File) = New List(Of File)() Using con As SqlConnection = New SqlConnection(cs) Dim cmd As SqlCommand = New SqlCommand(&#34;SELECT id,Name,path FROM tblFilesPath&#34;, con) cmd.CommandType = CommandType.Text con.Open() Dim rdr As SqlDataReader = cmd.ExecuteReader() While rdr.Read() Dim file As File = New File() file.Id = Convert.ToInt32(rdr(&#34;id&#34;)) file.Name = rdr(&#34;Name&#34;).ToString() file.Link = rdr(&#34;path&#34;).ToString() files.Add(file) End While End Using Dim js As JavaScriptSerializer = New JavaScriptSerializer() Context.Response.Write(js.Serialize(files)) End Sub End Class</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://i.imgur.com/eGnBiD2.gif" alt="" width="366" height="510" /></p>https://www.aspforums.net:443/Threads/281917/Get-Anchor-tag-HREF-Text-on-jQuery-DataTable-row-click-in-ASPNet/https://www.aspforums.net:443/Threads/281917/Get-Anchor-tag-HREF-Text-on-jQuery-DataTable-row-click-in-ASPNet/Wed, 10 Jul 2019 06:04:33 GMT