int records = 10000; int pages = 10; int pageSize = 15; SqlConnection conn = new SqlConnection("Server=(local);Database=megadata;User Id=sa;Password=xxx"); void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { dgBind(getSqlString(1)); } int firstPage = int.Parse(hidFirstPage.Value); pnlButtons.Controls.Add(getPager(firstPage)); lblPrompt.Text = "数据提取范围: <B>SELECT TOP " + records.ToString() + " megaid FROM megatable ORDER BY megaguid</B>"; } string getSqlString(int selectedPage) { string[] idsStrArray; string sqlStr; if (Session["idStr"] != null) { idsStrArray = Session["idStr"].ToString().Split('#'); } else { sqlStr = "SELECT TOP " + records.ToString() + " megaid FROM megatable ORDER BY megaguid"; SqlCommand cmd = new SqlCommand(sqlStr, conn); conn.Open(); SqlDataReader dr = cmd.ExecuteReader(); StringBuilder sb = new StringBuilder(""); int n = 1; while (dr.Read()) { if (n % pageSize == 0) { sb.Append(dr[0].ToString() + "#"); } else { sb.Append(dr[0].ToString() + ","); } |