asp.net中Datagrid分頁用法
asp.net中Datagrid分頁用法
/**//*;*計算總記錄的靜態函數。*本人在這里使用靜態函數的理由是:如果引用的是靜態數據或靜態函數,連接器會優化生成代碼,去掉動態重定位項(對。海量數據表分頁效果更明顯)。*希望大家給予意見、如有不正確的地方望指正。*/;public static int Calc()。{;int RecordCount = 0。SqlCommand MyCmd = new SqlCommand(";select count(*) as co from fdcproject";,MyCon())。SqlDataReader dr = MyCmd.ExecuteReader()。if(dr.Read())。
導讀/**//*;*計算總記錄的靜態函數。*本人在這里使用靜態函數的理由是:如果引用的是靜態數據或靜態函數,連接器會優化生成代碼,去掉動態重定位項(對。海量數據表分頁效果更明顯)。*希望大家給予意見、如有不正確的地方望指正。*/;public static int Calc()。{;int RecordCount = 0。SqlCommand MyCmd = new SqlCommand(";select count(*) as co from fdcproject";,MyCon())。SqlDataReader dr = MyCmd.ExecuteReader()。if(dr.Read())。
![](https://img.51dongshi.com/20250107/wz/18419009752.jpg)
接上/**//* *計算總記錄的靜態函數 *本人在這里使用靜態函數的理由是:如果引用的是靜態數據或靜態函數,連接器會優化生成代碼,去掉動態重定位項(對海量數據表分頁效果更明顯)。 *希望大家給予意見、如有不正確的地方望指正。*/public static int Calc(){int RecordCount = 0;SqlCommand MyCmd = new SqlCommand("select count(*) as co from fdcproject",MyCon());SqlDataReader dr = MyCmd.ExecuteReader();if(dr.Read())RecordCount = Int32.Parse(dr["co"].ToString());MyCmd.Connection.Close();return RecordCount;}//數據庫連接語句(從Web.Config中獲取)public static SqlConnection MyCon(){SqlConnection MyConnection = new SqlConnection(ConfigurationSettings.AppSettings["DSN2"]);MyConnection.Open();return MyConnection;}private void TDataBind(){CurrentPage = (int)ViewState["PageIndex"];//從ViewState中讀取頁碼值保存到CurrentPage變量中進行按鈕失效運算Pages = (int)ViewState["PageCounts"];//從ViewState中讀取總頁參數進行按鈕失效運算//判斷四個按鈕(首頁、上一頁、下一頁、尾頁)狀態if (CurrentPage + 1 > 1){Fistpage.Enabled = true;Prevpage.Enabled = true;}else{Fistpage.Enabled = false;Prevpage.Enabled = false;}if (CurrentPage == Pages){Nextpage.Enabled = false;Lastpage.Enabled = false;}else{Nextpage.Enabled = true;Lastpage.Enabled = true;}//數據綁定到DataList控件DataSet ds = new DataSet();//核心SQL語句,進行查詢運算(決定了分頁的效率:))SqlDataAdapter MyAdapter = new SqlDataAdapter("Select Top "+PageSize+" * from fdcproject where projid not in(select top "+PageSize*CurrentPage+" projid from fdcproject order by projid asc) order by projid asc",MyCon()); MyAdapter.Fill(ds,"news");datalist1.DataSource = ds.Tables["news"].DefaultView;datalist1.DataBind();//顯示Label控件LCurrentPaget和文本框控件gotoPage狀態LCurrentPage.Text = (CurrentPage+1).ToString();gotoPage.Text = (CurrentPage+1).ToString();//釋放SqlDataAdapterMyAdapter.Dispose();}
asp.net中Datagrid分頁用法
/**//*;*計算總記錄的靜態函數。*本人在這里使用靜態函數的理由是:如果引用的是靜態數據或靜態函數,連接器會優化生成代碼,去掉動態重定位項(對。海量數據表分頁效果更明顯)。*希望大家給予意見、如有不正確的地方望指正。*/;public static int Calc()。{;int RecordCount = 0。SqlCommand MyCmd = new SqlCommand(";select count(*) as co from fdcproject";,MyCon())。SqlDataReader dr = MyCmd.ExecuteReader()。if(dr.Read())。
為你推薦