dataGrid控件的自定义分页(已调试通过)


private void DataGNews_ItemCreated( object sender,System.Web.UI.WebControls.DataGridItemEventArgse)
... {
if(e.Item.ItemType==ListItemType.Pager)
...{

LinkButtonlb
=newLinkButton();
lb.Text
="首页";
e.Item.Controls[
0].Controls.AddAt(0,lb);
LinkButtonend
=newLinkButton();
end.Text
="末页";
e.Item.Controls[
0].Controls.Add(end);
lb.Click
+=newEventHandler(lb_Click);//添加事件处理程序
end.Click+=newEventHandler(end_Click);
HyperLinkzong
=newHyperLink();
zong.Text
=""+this.DataGNews.PageCount+"";
e.Item.Controls[
0].Controls.Add(zong);
HyperLinkper
=newHyperLink();
per.Text
="15条/页 ";
e.Item.Controls[
0].Controls.Add(per);
HyperLinkcur
=newHyperLink();
cur.Text
="当前页是"+(Convert.ToInt32(this.DataGNews.CurrentPageIndex)+1)+"页跳转到";
e.Item.Controls[
0].Controls.Add(cur);
DropDownListddl
=newDropDownList();
ddl.AutoPostBack
=true;//设置DropDownList控件的autopostback属性(自动回发)
for(inti=0;i<this.DataGNews.PageCount;i++)
...{
ddl.Items.Add(
newListItem(""+(i+1)+"",(i+1).ToString()));
}

ddl.SelectedIndexChanged
+=newEventHandler(ddl_SelectedIndexChanged);//添加下拉列表框的"选择改变时"所触发事件SelectedIndexChanged
e.Item.Controls[0].Controls.Add(ddl);
}

}

// 事件处理程序
public void lb_Click( object sender,System.EventArgse)
... {
this.DataGNews.CurrentPageIndex=0;
NewsBind();
}

// 事件处理程序

public void end_Click( object sender,System.EventArgse)
... {
this.DataGNews.CurrentPageIndex=this.DataGNews.PageCount-1;
NewsBind();
}

private void DataGNews_PageIndexChanged( object source,System.Web.UI.WebControls.DataGridPageChangedEventArgse)
... {
this.DataGNews.CurrentPageIndex=e.NewPageIndex;
NewsBind();
}

// 事件处理程序
public void ddl_SelectedIndexChanged( object sender,EventArgse)
... {
stringval=this.ddl.SelectedValue.ToString();
//Response.Write("<script>alert('"+val+"')</script>");
this.DataGNews.CurrentPageIndex=int.Parse(val)-1;
this.NewsBind();
this.ddl.SelectedValue=(int.Parse(val)).ToString();
}

你可能感兴趣的:(datagrid)