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.Update Database based on HTML Table Row CheckBox checked using jQuery AJAX and Web Service in C# and VB.Net<p>Hi&nbsp;<a class="username" rel="jovceka">jovceka,</a></p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <pre class="brush: html">&lt;table id=&#34;example&#34;&gt; &lt;tr&gt; &lt;th&gt; ProductName &lt;/th&gt; &lt;th&gt; Proddetails &lt;/th&gt; &lt;th&gt; Status &lt;/th&gt; &lt;/tr&gt; &lt;/table&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34;&gt; $(function () { GetProduct(); }); function Checked(ele) { var id = $(ele).attr(&#34;data-id&#34;); var pdtstatus = &#34;&#34;; var isChecked = $(ele).is(&#34;:checked&#34;); if (isChecked) { PdtStatus = &#34;true&#34;; } else { PdtStatus = &#34;false&#34;; } $.ajax({ type: &#34;Post&#34;, contentType: &#34;application/json; charset=utf-8&#34;, url: &#34;WebService.asmx/UpdeateStatus&#34;, data: &#39;{PdtStatus:&#39; + PdtStatus + &#39;,eid:&#39; + id + &#39;}&#39;, datatype: &#34;json&#34;, success: function (data) { if (data.d &gt; 0) { alert(&#34;ProductId &#34; + id + &#34; Updated Successfully&#34;); } }, error: function (data) { alert(&#34;Error while Updating data of :&#34; + id); } }); } function GetProduct() { $.ajax({ type: &#34;POST&#34;, contentType: &#34;application/json; charset=utf-8&#34;, url: &#34;WebService.asmx/Products&#34;, data: {}, dataType: &#34;json&#34;, success: function (data) { var table = $(&#39;#example&#39;); var rows = &#34;&#34;; for (var i = 0; i &lt; data.d.length; i++) { var name = data.d[i].ProductName; var details = data.d[i].Proddetails; var status = data.d[i].Status; rows += &#34;&lt;tr&gt;&lt;td&gt;&#34; + name + &#34;&lt;/td&gt;&lt;td&gt;&#34; + details + &#34;&lt;/td&gt;&#34;; if (status == &#34;true&#34;) { rows += &#34;&lt;td&gt;&lt;input type=checkbox onclick=Checked(this) data-id=&#39;&#34; + data.d[i].ProductId + &#34;&#39; id=chk1 checked=checked &gt;&lt;/td&gt;&lt;/tr&gt;&#34;; } else { rows += &#34;&lt;td&gt;&lt;input type=checkbox onclick=Checked(this) data-id=&#39;&#34; + data.d[i].ProductId + &#34;&#39; id=chk1 &gt;&lt;/td&gt;&lt;/tr&gt;&#34;; } } table.append(rows); }, error: function (response) { alert(&#34;Error while Showing update data&#34;); } }); } &lt;/script&gt;</pre> <p><strong><span style="text-decoration: underline;">C#</span></strong></p> <pre class="brush: csharp">using System.Collections.Generic; using System.Web.Services; using System.Configuration; using System.Data.SqlClient; /// &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 { [WebMethod] public List&lt;Product&gt; Products() { List&lt;Product&gt; productList = new List&lt;Product&gt;(); productList.Add(new Product { ProductId = 1, ProductName = &#34;Chai&#34;, Proddetails = &#34;Soft drinks, coffees, teas, beers, and ales&#34;, Status = &#34;true&#34; }); productList.Add(new Product { ProductId = 2, ProductName = &#34;Aniseed Syrup&#34;, Proddetails = &#34;Sweet and savory sauces, relishes, spreads, and seasonings&#34;, Status = &#34;false&#34; }); productList.Add(new Product { ProductId = 3, ProductName = &#34;Manjimup Dried Apples&#34;, Proddetails = &#34;Dried fruit and bean curd&#34;, Status = &#34;false&#34; }); productList.Add(new Product { ProductId = 4, ProductName = &#34;Carnarvon Tigers&#34;, Proddetails = &#34;Seaweed and fish&#34;, Status = &#34;true&#34; }); return productList; } [WebMethod] public int UpdeateStatus(string PdtStatus, string eid) { int i = 0; // Code for updating Status column in Database. string conString = ConfigurationManager.ConnectionStrings[&#34;constr&#34;].ConnectionString; string query = &#34;UPDATE Orders SET Status = @Status WHERE ProductId = @Id&#34;; SqlCommand cmd = new SqlCommand(query); using (SqlConnection con = new SqlConnection(conString)) { cmd.Connection = con; cmd.Parameters.AddWithValue(&#34;@Status&#34;, PdtStatus); cmd.Parameters.AddWithValue(&#34;@Id&#34;, eid); con.Open(); i = cmd.ExecuteNonQuery(); con.Close(); } return i; } public class Product { public int ProductId { get; set; } public string ProductName { get; set; } public string Proddetails { get; set; } public string Status { get; set; } } } </pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Collections.Generic Imports System.Web.Services Imports System.Configuration Imports System.Data.SqlClient &lt;WebService([Namespace]:=&#34;http://tempuri.org/&#34;)&gt; &lt;WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)&gt; &lt;System.Web.Script.Services.ScriptService&gt; Public Class WebService Inherits System.Web.Services.WebService &lt;WebMethod&gt; Public Function Products() As List(Of Product) Dim productList As List(Of Product) = New List(Of Product)() productList.Add(New Product With { .ProductId = 1, .ProductName = &#34;Chai&#34;, .Proddetails = &#34;Soft drinks, coffees, teas, beers, and ales&#34;, .Status = &#34;true&#34; }) productList.Add(New Product With { .ProductId = 2, .ProductName = &#34;Aniseed Syrup&#34;, .Proddetails = &#34;Sweet and savory sauces, relishes, spreads, and seasonings&#34;, .Status = &#34;false&#34; }) productList.Add(New Product With { .ProductId = 3, .ProductName = &#34;Manjimup Dried Apples&#34;, .Proddetails = &#34;Dried fruit and bean curd&#34;, .Status = &#34;false&#34; }) productList.Add(New Product With { .ProductId = 4, .ProductName = &#34;Carnarvon Tigers&#34;, .Proddetails = &#34;Seaweed and fish&#34;, .Status = &#34;true&#34; }) Return productList End Function &lt;WebMethod&gt; Public Function UpdeateStatus(ByVal PdtStatus As String, ByVal eid As String) As Integer Dim i As Integer = 0 Dim conString As String = ConfigurationManager.ConnectionStrings(&#34;constr&#34;).ConnectionString Dim query As String = &#34;UPDATE Orders SET Status = @Status WHERE ProductId = @Id&#34; Dim cmd As SqlCommand = New SqlCommand(query) Using con As SqlConnection = New SqlConnection(conString) cmd.Connection = con cmd.Parameters.AddWithValue(&#34;@Status&#34;, PdtStatus) cmd.Parameters.AddWithValue(&#34;@Id&#34;, eid) con.Open() i = cmd.ExecuteNonQuery() con.Close() End Using Return i End Function Public Class Product Public Property ProductId As Integer Public Property ProductName As String Public Property Proddetails As String Public Property Status As String End Class 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/6f8c2FS.gif" alt="" width="472" height="180" /></span></strong></p>https://www.aspforums.net:443/Threads/109846/Update-Database-based-on-HTML-Table-Row-CheckBox-checked-using-jQuery-AJAX-and-Web-Service-in-C-and-VBNet/https://www.aspforums.net:443/Threads/109846/Update-Database-based-on-HTML-Table-Row-CheckBox-checked-using-jQuery-AJAX-and-Web-Service-in-C-and-VBNet/Mon, 03 Dec 2018 02:21:19 GMT