我在我的项目中遇到了这个问题,因为我只是重新生成相同的问题,我创建了测试项目,但问题仍然存在。
我有一个网格视图。我最初用一些值绑定它,点击按钮后,我用不同的数据源绑定它。但它显示了相同的数据。
C#:
public partial class Default : System.Web.UI.Page
{
static Default def;
protected void Page_Load(object sender, EventArgs e)
{
grdTest.DataSource = new List<Employee> {
new Employee {Age = "26", Gender = "Male", Name = "A"},
new Employee {Age = "26", Gender = "Male", Name = "B"},
new Employee {Age = "26", Gender = "Male", Name = "C"}
};
grdTest.DataBind();
def = this;
}
public void Bind()
{
GridView gr = (GridView)def.FindControl("grdTest");
gr.DataSource = null;
gr.DataSource = new List<Employee> {
new Employee {Age = "26", Gender = "Male", Name = "A"},
new Employee {Age = "26", Gender = "Male", Name = "B"},
new Employee {Age = "26", Gender = "Male", Name = "C"},
new Employee {Age = "26", Gender = "Male", Name = "D"}
};
gr.DataBind();
}
[WebMethod]
public static void TestMethod()
{
def.Bind();
}
}
public class Employee
{
public string Name { get; set; }
public string Gender { get; set; }
public string Age { get; set; }
}
JQuery的:
$(document).ready(function () {
$("[id*=btnTest]").click(
function () {
$.ajax({
type: "POST",
url: "Default.aspx/TestMethod",
contentType: "application/json; charset=utf-8",
dataType: "json",
// Passes id of current instance of user control
//data: "{ 'currentId': '" + $(input).attr("id").split("_").reverse()[1] + "' }",
success: function (response) {
},
failure: function (response) {
}
});
});
});