I have a WebMethod
in my aspx.cs
which is being called on the client side via jquery using an Ajax POST Request
when an ASP:Label
is being clicked.
The WebMethod
points to another method in the aspx.cs
and actually retrieve a DataTable
which is used to populate the Gridview
and then display it.
WebMethod and other method (aspx) :
[System.Web.Services.WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static void ViewDetailsItemOrdersWS(String ddlTimeSelectedVal)
{
Index i = new Index();
i.itemOrder(ddlTimeSelectedVal);
}
protected void itemOrder(String ddlTimeSelectedVal) {
//try
//{
int val = Convert.ToInt32(ddlTimeSelectedVal);
//PlaceHolder placeholder1 = new PlaceHolder();
//placeholder1.Controls.Add(gvList);
DataTable s = new DataTable();
s = getMenuData(val);
Debug.WriteLine(s.Rows.Count);
gvList.DataSource = s;
gvList.DataBind();
gvList.Visible = true;
//}
//catch (Exception ex)
//{
// Debug.WriteLine(ex.ToString());
//}
}
Client's side codes :
$(document).ready(function () {
var dataDDLTime = $('.<%= ddlTime.ClientID %>').val();
$('#<%= lblItemOrders.ClientID %>').on('click', function () {
var dataOfDDLTime = JSON.stringify({ ddlTimeSelectedVal: dataDDLTime });
alert(dataOfDDLTime);
if ($('[id$=gvList]') != undefined) {
$.ajax({
type: "POST",
url: "Index.aspx/ViewDetailsItemOrdersWS",
data: dataOfDDLTime,
contentType: 'application/json; charset=utf-8',
dataType: "json",
success: function (data) {
},
error: function (err) {
console.log(err);
}
});
} else {
console.log('gvList not found.');
}
});
});
I got this error. I checked the DataTable
returned, apparently the number of rows isn't 0. I can't tell what's the issue with the Gridview
being null.
Appreciate any help, thanks!