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.Apply word wrap in jQuery DataTable Column using jQuery in ASP.Net<p>Hi&nbsp;jovceka,</p> <p>Wrap the column data in a div and set the white-space and width css properties for the div.</p> <p>Check this example. Now please take its reference and correct your code.</p> <p>Database</p> <p>For this example I have used of Northwind database that you can download using the link given below.</p> <p><a href="https://www.aspsnippets.com/Articles/Install-Microsoft-Northwind-and-Pubs-Sample-databases-in-SQL-Server-Management-Studio.aspx" target="_blank">Download Northwind Database</a></p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></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;script type=&#34;text/javascript&#34; src=&#34;http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js&#34;&gt;&lt;/script&gt; &lt;script src=&#34;https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js&#34; type=&#34;text/javascript&#34;&gt;&lt;/script&gt; &lt;script src=&#34;https://cdn.datatables.net/1.10.13/js/dataTables.bootstrap.min.js&#34; type=&#34;text/javascript&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;https://cdn.datatables.net/responsive/2.1.1/js/dataTables.responsive.min.js&#34;&gt;&lt;/script&gt; &lt;link rel=&#34;stylesheet&#34; type=&#34;text/css&#34; href=&#34;https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css&#34; /&gt; &lt;link rel=&#34;stylesheet&#34; type=&#34;text/css&#34; href=&#34;https://cdn.datatables.net/1.10.13/css/dataTables.bootstrap.min.css&#34; /&gt; &lt;link rel=&#34;stylesheet&#34; type=&#34;text/css&#34; href=&#34;https://cdn.datatables.net/responsive/2.1.1/css/responsive.bootstrap.min.css&#34; /&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;https://cdnjs.cloudflare.com/ajax/libs/jquery-browser/0.1.0/jquery.browser.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34;&gt; $(function () { $.ajax({ url: &#39;&lt;%= Page.ResolveUrl(&#34;~/WebService.asmx/GetCustomers&#34;)%&gt;&#39;, method: &#39;post&#39;, dataType: &#39;json&#39;, success: function (data) { $(&#39;#datatable&#39;).dataTable({ &#34;processing&#34;: true, &#34;paging&#34;: true, &#34;searching&#34;: { &#34;regex&#34;: true }, &#34;responsive&#34;: true, data: data, columns: [ { &#39;data&#39;: &#39;Id&#39;, width: &#34;50px&#34; }, { &#39;data&#39;: &#39;Name&#39;, width: &#34;100px&#34; }, { &#39;data&#39;: &#39;Notes&#39; }, ], columnDefs: [{ render: function (data, type, full, meta) { return &#34;&lt;div id=&#39;dvNotes&#39; style=&#39;white-space: normal;width: 250px;&#39;&gt;&#34; + data + &#34;&lt;/div&gt;&#34;; }, targets: 2 }] }); } }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form id=&#34;form1&#34; runat=&#34;server&#34;&gt; &lt;table id=&#34;datatable&#34; class=&#34;table table-striped table-bordered dt-responsive&#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;Notes&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;/table&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt;</pre> <p><strong><span style="text-decoration: underline;">WebService</span></strong></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Data.SqlClient; using System.Web.Script.Serialization; using System.Web.Services; [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 Customer { public int Id { get; set; } public string Name { get; set; } public string Notes { get; set; } } [WebMethod] public void GetCustomers() { string cs = ConfigurationManager.ConnectionStrings[&#34;constr&#34;].ConnectionString; List&lt;Customer&gt; customers = new List&lt;Customer&gt;(); using (SqlConnection con = new SqlConnection(cs)) { SqlCommand cmd = new SqlCommand(&#34;SELECT EmployeeId,FirstName,Notes FROM Employees&#34;, con); cmd.CommandType = CommandType.Text; con.Open(); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { Customer customer = new Customer(); customer.Id = Convert.ToInt32(rdr[&#34;EmployeeId&#34;]); customer.Name = rdr[&#34;FirstName&#34;].ToString(); customer.Notes = rdr[&#34;Notes&#34;].ToString(); customers.Add(customer); } } JavaScriptSerializer js = new JavaScriptSerializer(); Context.Response.Write(js.Serialize(customers)); } } </pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Collections.Generic Imports System.Configuration Imports System.Data Imports System.Data.SqlClient Imports System.Web.Script.Serialization Imports System.Web.Services &#39; To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. &#39; &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 Customer Public Property Id As Integer Public Property Name As String Public Property Notes As String End Class &lt;WebMethod()&gt; Public Sub GetCustomers() Dim cs As String = ConfigurationManager.ConnectionStrings(&#34;constr&#34;).ConnectionString Dim customers As List(Of Customer) = New List(Of Customer)() Using con As SqlConnection = New SqlConnection(cs) Dim cmd As SqlCommand = New SqlCommand(&#34;SELECT EmployeeId,FirstName,Notes FROM Employees&#34;, con) cmd.CommandType = CommandType.Text con.Open() Dim rdr As SqlDataReader = cmd.ExecuteReader() While rdr.Read() Dim customer As Customer = New Customer() customer.Id = Convert.ToInt32(rdr(&#34;EmployeeId&#34;)) customer.Name = rdr(&#34;FirstName&#34;).ToString() customer.Notes = rdr(&#34;Notes&#34;).ToString() customers.Add(customer) End While End Using Dim js As JavaScriptSerializer = New JavaScriptSerializer() Context.Response.Write(js.Serialize(customers)) End Sub End Class</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><strong><span style="text-decoration: underline;"><img src="https://i.imgur.com/IHgeIMa.jpg" alt="" width="348" height="369" /></span></strong></p>https://www.aspforums.net:443/Threads/196072/Apply-word-wrap-in-jQuery-DataTable-Column-using-jQuery-in-ASPNet/https://www.aspforums.net:443/Threads/196072/Apply-word-wrap-in-jQuery-DataTable-Column-using-jQuery-in-ASPNet/Tue, 23 Jul 2019 08:40:00 GMT