My code behind in SampleService.asmx file is ie working
[System.Web.Script.Services.ScriptService]
public class SampleService : System.Web.Services.WebService {
[WebMethod]
public string LoadData()
{
string constr = ConfigurationManager.ConnectionStrings["SqlCon"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
DataTable table = new DataTable();
SqlCommand cmd = new SqlCommand("SELECT top 10 CustomerID,CompanyName,ContactName,ContactTitle,Address, City,Region, PostalCode, Country, Phone, Fax FROM Customers");
cmd.Connection = con;
con.Open();
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(table);
con.Close();
JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
List> parentRow = new List>();
Dictionary childRow;
foreach (DataRow row in table.Rows)
{
childRow = new Dictionary();
foreach (DataColumn col in table.Columns)
{
childRow.Add(col.ColumnName, row[col]);
}
parentRow.Add(childRow);
}
return jsSerializer.Serialize(parentRow);
}
}
and my jquery page service call is as follows
<pre><%@ Page Language="C#" AutoEventWireup="true" CodeFile="DataTablePage.aspx.cs" EnableEventValidation="false" Inherits="DataTablePage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta name="viewport" content="width=device-width" />
<title>ShowGrid</title>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link href="css/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="https://cdn.datatables.net/1.10.15/css/dataTables.bootstrap.min.css" rel="stylesheet" />
<link href="https://cdn.datatables.net/responsive/2.1.1/css/responsive.bootstrap.min.css" rel="stylesheet" />
<script type="text/javascript" src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.15/js/dataTables.bootstrap4.min.js "></script>
<script type="text/javascript">
$(document).ready(function () {
debugger;
$("#demoGrid").DataTable({
"processing": true,
"serverSide": true,
"filter": true,
"orderMulti": false,
"pageLength": 100,
"ajax": {
"type": "POST",
"url": "SampleService.asmx/LoadData",
"data": "{}",
"contentType": "application/json; charset=utf-8",
"dataType": "json"
},
"columnDefs":
[{
"targets": [0],
"visible": true,
"searchable": false
},
{
"targets": [2],
"visible": true,
"searchable": true
},
{
"targets": [7],
"searchable": false,
"orderable": false
},
{
"targets": [8],
"visible": false,
"searchable": false,
"orderable": false
},
{
"targets": [9],
"visible": false,
"searchable": false,
"orderable": false
}],
"columns": [
{ "data": "CustomerID", "name": "CustomerID", "autoWidth": true },
{ "data": "CompanyName", "name": "CompanyName", "autoWidth": true },
{ "data": "ContactName", "title": "ContactName", "name": "ContactName", "autoWidth": true },
{ "data": "ContactTitle", "name": "ContactTitle", "autoWidth": true },
{ "data": "City", "name": "City", "autoWidth": true },
{ "data": "PostalCode", "name": "PostalCode", "autoWidth": true },
{ "data": "Country", "name": "Country", "autoWidth": true },
{ "data": "Phone", "name": "Phone", "title": "Status", "autoWidth": true },
{
"render": function (data, type, full, meta) {
return '<a class="btn btn-info" href="/Demo/Edit/' + full.CustomerID + '">Edit</a>';
}
}
,
{
data: null, render: function (data, type, row) {
return "<a href='#' class='btn btn-danger' onclick=DeleteData('" + row.CustomerID + "'); >Delete</a>";
}
},
]
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div class="container">
<br />
<div style="width:90%; margin:0 auto;">
<table id="demoGrid" class="table table-striped table-bordered dt-responsive nowrap" width="100%" cellspacing="0">
<thead>
<tr>
<th>CustomerID</th>
<th>CompanyName</th>
<th>ContactName</th>
<th>ContactTitle</th>
<th>City</th>
<th>PostalCode</th>
<th>Country</th>
<th>Phone</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
</form>
</body>
</html>
What I have tried:
I am unable to connect the <pre>SampleService.asmx function LoadData()
I have do the same in mvc its working but here in asp.net I have trouble. Please any one can help