/// <summary>
/// 根据pageCount和pageIndex实现分页功能以及删除提示
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton del = (LinkButton)e.Row.Cells[1].Controls[0];
del.Attributes.Add("onclick", "javascript:return confirm('是否删除?');");
}
if (e.Row.RowType == DataControlRowType.Pager)
{
Label pagecount = e.Row.FindControl("lblpagecount") as Label;
pagecount.Text = "一共有" + this.GridView1.PageCount.ToString() + "页";
Label pageindex = e.Row.FindControl("lblpageindex") as Label;
pageindex.Text ="当前页是第"+(this.GridView1.PageIndex + 1).ToString()+"页";
LinkButton lbutfrist = e.Row.FindControl("lbFirst") as LinkButton;
LinkButton lbutpres = e.Row.FindControl("lbPres") as LinkButton;
LinkButton lbutnest = e.Row.FindControl("lbNest") as LinkButton;
LinkButton lbutlast = e.Row.FindControl("lblast") as LinkButton;
int pagecounts = this.GridView1.PageCount;
int pageindexs = this.GridView1.PageIndex;
if (lbutfrist != null)
{
lbutfrist.Enabled = pageindexs > 0 && pagecounts > 1;
}
if (lbutpres != null)
{
lbutpres.Enabled = pageindexs > 0 && pagecounts > 1;
}
if (lbutnest != null)
{
lbutnest.Enabled = pagecounts > 1 && pageindexs < pagecounts - 1;
}
if (lbutlast!= null)
{
lbutlast.Enabled = pagecounts > 1 && pageindexs < pagecounts - 1;
}
}
//绑定Dripdownlist以及index发生变化时的事件
DropDownList ddlist = e.Row.FindControl("ddlist") as DropDownList;
if (ddlist != null)
{
for (int i = 0; i < this.GridView1.PageCount; i++)
{
ddlist.Items.Add(new ListItem((i + 1).ToString(), i.ToString()));
}
ddlist.SelectedIndex = this.GridView1.PageIndex;
ddlist.SelectedIndexChanged += new EventHandler(GridView1_SelectedIndexChanged);
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddpageinde = (DropDownList)sender;
this.GridView1.PageIndex = Convert.ToInt32(ddpageinde.SelectedValue);
bindgv();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
if (this.GridView1.PageIndex < 0)
{
this.GridView1.PageIndex = 0;
}
else
{
this.GridView1.PageIndex = e.NewPageIndex;
bindgv();
}
}