private void LinkButton1_Click(object sender, System.EventArgs e)
{
this.dtgEmployee.CurrentPageIndex=0;
this.DataGridBind();
}
private void LinkButton2_Click(object sender, System.EventArgs e)
{
this.dtgEmployee.CurrentPageIndex=this.dtgEmployee.PageCount-1;
this.DataGridBind();
}
在DataGrid的ItemCreated中:
if (e.Item.ItemType == ListItemType.Pager)
{
LinkButton btnFirst = new LinkButton();
btnFirst.Text = "First";
btnFirst.Click += new System.EventHandler(btn_Click);
e.Item.Cells[0].Controls.AddAt(0, btnFirst);
LinkButton btnLast = new LinkButton();
btnLast.Text = "Last";
btnLast.Click += new System.EventHandler(btn_Click);
e.Item.Cells[0].Controls.Add(btnLast);
}
...
private void btn_Click(object sender, EventArgs e)
{
LinkButton btn = (LinkButton)sender;
if (btn.Text == "First");
DataGrid1.CurrentPageIndex = 0;
else if (btn.Text == "Last")
DataGrid1.CurrentPageIndex = DataGrid1.PageCount - 1;
DataGrid1.DataBind();
}