【发布时间】:2011-02-11 01:33:13
【问题描述】:
我在更新面板中有一个gridview,我有一个使用jquery 调用页面方法的javascript。我希望页面方法根据它从 ajax 调用接收到的参数刷新 gridview。
到目前为止,我有以下内容:
1)在javascript中,有一个调用page方法的函数:
function GetNewDate(thedateitem) {
DateString = (valid json date format that works)
$.ajax({
type: "POST",
url: "./CallHistory.aspx/ResetDate",
contentType: "application/json; charset=utf-8",
data: DateString,
dataType: "json",
success: successFn,
error: errorFn
})
};
2)在我的aspx页面中:
<asp:UpdatePanel ID="MyPanel" runat="server">
<ContentTemplate>
<asp:GridView ID="MyGrid">
3) 在后面的代码中:
public partial class Pages_CallHistory : System.Web.UI.Page
{
List<ViewCallHistoryModel> TheCallHistory;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
TheDate = new DateTime(2011, 1, 13);
LoadCallHistory(TheDate);
MyGrid.Datasource = TheCallHistory;
MyGrid.Databind;
}
}
protected void LoadCallHistory(DateTime TheDate)
{
linq query that fills the variable TheCallHistory
}
[WebMethod]
public static void ResetDate(DateTime TheNewDate)
{
var test = new Pages_CallHistory();
var test2 = test.LoadCallHistory(TheNewDate.Date);
//test2 loads fine
test.GridCallHistory.DataSource = test2;
//this is not underlined but bugs at runtime
//Object reference not set to an instance of an object.
test.GridCallHistory.DataBind();
test.MyPanel.Update();
//this is not underlined but doesn't get executed because
//because it stops at the line above
//I'd like to update the content of
//the gridview on the page with the updated gridview.
}
我想在 page 方法中做的是 1) 使用新的日期参数调用 LoadCallHistory 和 2) 告诉 gridview MyGrid 使用 TheCallHistory 中的新数据重新绑定。
我正在努力使用这种页面方法;它不起作用,我被卡住了。这是怎么做到的?
【问题讨论】:
-
为什么会失败?你得到什么结果?您是否尝试过设置断点并在调试模式下单步执行代码以确保“TheCallHistory”具有应有的数据?另外,您确定 gridview 可以绑定到诸如 List
之类的源吗? -
页面上的内容比我可以发布的要多,但简而言之,是的,页面加载时一切正常。更新面板内还有排序和分页功能,无需刷新即可工作。到目前为止,在页面方法中我有: var test = new Pages_CallHistory(); test.LoadCallHistory(TheNewDate.Date);我需要绑定 MyGrid 并将其放到页面中。
标签: asp.net