i try to convert var dq in dataset and then i want to display this data in gridview for this i try this
`
[WebMethod]
public static DataTable search_data(DateTime fromdate, DateTime todate, string regiondrop)
{
try
{
T1 ts = new Ts1();
var dq = (from vv in ts.tblVe
join rv in ts.tblReg on vv.ID equals rv.ID
join re in ts.tblRegio 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,
ownername = rv.OwnerName,
RegNo = rv.RegNo,
Speed = rv.Speed,
}).ToList();
DataView view = dq.AsDataView();
}
catch (Exception)
{
throw new Exception();
}
}`
in dq the data is
[0] = { ID = 1, OName = "Kan", RegNo = "AJ-24",Speed = "124" }
[1] = { ID = 2, OName = "Shh", RegNo = "AL-91",Speed = "95" }
and in jquery i try to bind gridview
$(function () {
$.ajax({
type: "POST",
url: "WebForm1.aspx/search_data",
// data: JSON.stingify(obj),
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 (data.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 < data.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>");
}
}
}
});
});
`
now how i return and display data in gridview
this shows error when i try this line
DataView view = dq.AsDataView();
Error 3 Instance argument: cannot convert from 'System.Collections.Generic.List' to 'System.Data.DataTable'
Error 4 'System.Collections.Generic.List' does not contain a definition for 'AsDataView' and the best extension method overload 'System.Data.DataTableExtensions.AsDataView(System.Data.DataTable)' has some invalid arguments