protected void GridViewOverTime_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView theGrid = sender as GridView; // refer to the GridView int newPageIndex = 0; if (-2 == e.NewPageIndex) { // when click the "GO" Button TextBox txtNewPageIndex = null; GridViewRow pagerRow = GridViewOverTime.BottomPagerRow; if (null != pagerRow) { txtNewPageIndex = (TextBox)pagerRow.FindControl("textbox"); // refer to the TextBox with the NewPageIndex value } if (null != txtNewPageIndex && txtNewPageIndex.Text != "") { newPageIndex = int.Parse(txtNewPageIndex.Text) - 1; // get the NewPageIndex } } else { // when click the first, last, previous and next Button newPageIndex = e.NewPageIndex; } // check to prevent form the NewPageIndex out of the range if (Label_Grid1_State.Text == "默认数据源") { Session["BindTable"] = OverTimeOption.BindOverTime(); BindData(); UpdatePanelList.Update(); } if (Label_Grid1_State.Text == "模糊搜索数据源") { Session["BindTable"] = OverTimeOption.SearchOverTime(TextBoxOverTime.Text.Trim()); BindData(); UpdatePanelList.Update(); } //绑定数据源 //bindgridview(); newPageIndex = newPageIndex < 0 ? 0 : newPageIndex; newPageIndex = newPageIndex >= GridViewOverTime.PageCount ? GridViewOverTime.PageCount - 1 : newPageIndex; // specify the NewPageIndex GridViewOverTime.PageIndex = newPageIndex; GridViewOverTime.PageIndex = newPageIndex; GridViewOverTime.DataBind(); }
/// <summary> /// 函数名:BindData /// 作用:绑定GridViewOverTime的数据 /// 作者:开济 /// </summary> private void BindData() { GridViewOverTime.DataSource = Session["BindTable"]; GridViewOverTime.DataBind(); }