我正在使用 asp.net 的网格视图 Web 控件,我在其中使用分页控件,我在其中处理了分页事件,但是如果我单击 2、3、4 则它不显示数据...等等链接它不显示一个结果集..它没有给出任何异常,但只显示第一页。这里是代码:
public partial class Main : System.Web.UI.Page
{
protected string PostBackOption = "";
protected void Page_Load(object sender, EventArgs e)
{
this.check.Text = " ";
if (Page.IsPostBack)
{
PostBackOption = "$(\"#dialog\").dialog(\"open\");";
}
}
List<Allemployees> result1 = new List<Allemployees>();
protected void Button1_Click(object sender, EventArgs e)
{ // Show all the employees currently in the table
GridView1.DataSource = null;
GridView1.DataBind();
using (var db = new AdventureWorks2012_DataEntities())
{
List<Allemployees> result = new List<Allemployees>();
var query = from b in db.Employees
join p in db.People on b.BusinessEntityID equals p.BusinessEntityID
orderby p.BusinessEntityID
select new
{
b.BusinessEntityID,
p.FirstName,
p.LastName
};
foreach (var item in query)
{
Allemployees t1 = new Allemployees();
t1.BusinessEntityId = item.BusinessEntityID;
t1.FirstName = item.FirstName;
t1.LastName = item.LastName;
result1.Add(t1);
}
GridView1.DataSource = result1;
GridView1.DataBind();
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = result1;
GridView1.DataBind();
}
}