我的WebMethod
中有一个aspx.cs
,当点击Ajax POST Request
时,使用ASP:Label
通过jquery在客户端调用。{/ p>
WebMethod
指向aspx.cs
中的另一个方法并实际检索DataTable
,用于填充Gridview
然后显示它。
WebMethod和其他方法(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());
//}
}
客户端代码:
$(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.');
}
});
});
我收到了这个错误。我检查了返回的DataTable
,显然行数不是0.我无法说明Gridview
为空的问题。
感谢任何帮助,谢谢!