i try to return data in web method using linq .. and also i bind grid view in jquery
What I have tried:
UPDATED CODE
<script type="text/javascript">
var strArray = "[['sfdsdfLi', 9],['Kiwsdfi', 3],['Mixesdfd nuts', 1],['Oranges', 6],['Grapes (bunch)', 1]]";
$(function () {
$('[ID*=search_data]').on('click', function () {
var from = $('[ID*=fromdate]').val();
var to = $('[ID*=todate]').val();
var reg = $('[ID*=regiondrop] option:selected')[0].value;
var obj = {};
obj.fdate = from;
obj.tdate = to;
obj.region = reg;
Getdata(obj);
return false;
});
});
$(function () {
$('[ID*=search_data]').on('click', function () {
var fromdate = $('[ID*=fromdate]').val();
var todate = $('[ID*=todate]').val();
var regiondrop = $('[ID*=regiondrop] option:selected')[0].value;
var GridView1 = $('[ID*=GridView1]');
var obj = {};
obj.fdate = from;
obj.tdate = to;
obj.region = reg;
Getdataa(obj);
});
});
function Getdataa(obj) {
$.ajax({
type: "POST",
url: "WebForm1.aspx/search_data",
data: "{'fromdate':'" + fromdate + "','todate':'" + todate + "','regiondrop':'" + regiondrop + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
cache: false,
success: function (result) {
$("#GridView1").empty();
if (result.d.length > 0) {
$("#GridView1").append(
"<tr><th>Owner Name</th><th>Reg No</th><th>Mileage Accumlation</th><th>MaxSpeed</th>");
for (var i = 0; i < result.d.length; i++) {
$("#GridView1").append("<tr><td>" +
data.d[i].OwnerName + "</td> <td>" +
data.d[i].RegNo + "</td> <td>" +
data.d[i].MileageAccumlation + "</td> <td>" +
data.d[i].MaxSpeed + "</td></tr>");
}
}
else {
$("#GridView1").hide();
$("#Label1").text("No Data");
}
},
error: function (error) {
alert("error");
}
});
}
function Getdata(obj) {
$.ajax({
type: "POST",
url: "WebForm1.aspx/GetVo",
data: JSON.stringify(obj),
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
cache: false,
success: function (result) {
strarr = result.d;
var myarr = strarr;
Drewchart(myarr);
},
error: function (error) {
alert("error");
}
});
}
function Drewchart(result) {
$('#container').highcharts({
chart: {
type: 'pie',
options3d: {
enabled: true,
alpha: 45
}
},
title: {
text: 'Contents of Charts'
},
subtitle: {
text: '3D donut in Highcharts'
},
plotOptions: {
pie: {
innerSize: 100,
depth: 45
}
},
series: [{
name: 'Delivered amount',
data: result
}]
});
}
webmthod
[WebMethod]
[WebMethod]
public static DataTable search_data(DateTime fromdate, DateTime todate, string regiondrop)
{
try
{
TrackDataEntities1 ts = new TrackDataEntities1();
var dq = (from vv in ts.tblVe
join rv in ts.tblReg on vv.ID equals rv.ID
join re in ts.tblRegi on rv.RID equals re.RID
where
re.Region == regiondrop
&& re.StartDate <= fromdate
&& re.EndDate >= todate
orderby
vv.ID,
rv.OwnerName
select new
{
ID = vv.ID,
oname = rv.OName,
RegNo = rv.RegNo,
Speed = rv.Speed,
});
DataTable dt = new DataTable();
dt.Rows.Add(dq);
return dt;
}
catch (Exception)
{
throw new Exception();
}
}
this show error
WebForm1.aspx:70 Uncaught ReferenceError: regiondrop is not defined
http://localhost:33578/WebForm1.aspx/GetVo Failed to load resource: the server responded with a status of 500 (Internal Server Error)