|
|
الرئيسية
| آخر المواضيع
| المتصلين
| مستخدم جديد
| بحث
| مساعدة
| |
![]() |
mvnForum » قائمة المنتديات » منتدى: Games Programming Forum » مشاركة: New solution in Gridview paging |
|
مجموع الردود في هذا المشاركة: 2 |
[إضافة إلى لمفضلة] [شاهد هذه المشاركة] [موضوع جديد] |
| الكاتب |
|
|
Member Egypt تاريخ الاشتراك: 27/11/2006 عدد الردود: 72 حالة الإيصال: غير متصل |
السلام عليكم ورحمة الله و بركاته من فضل الله . ربنا من عليه بحل لموضوع paging انا جربت الحل ده علي تيبل فيه 61.000 record ووجدت ان مفيس اي مشكله في الجرد و كمان السرعه اكبر بكتير جداً جداً storedProcedure set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER procedure [dbo].[Test_GetClientsByPage] @SelectedID as int, @MoveState as nvarchar (5) ,@TotalRecords as int Output as --Set no count on set nocount on --Determin which move IF @MoveState='First' Select top 5 * From BookChapters else if @MoveState = 'Prv' select * from (Select top 5 * From BookChapters Where BookChapter_ID < @SelectedID order by BookChapter_ID desc) as BookChapters order by BookChapter_ID else if @MoveState='Last' select * from ( Select top 5 * From BookChapters Order by BookChapter_ID desc) as BookChapters order by BookChapter_ID else if @MoveState='Next' Select top 5 * From BookChapters Where BookChapter_ID > @SelectedID --Return the total number of records available as an output parameter Select @TotalRecords = Count(*) From BookChapters * Code in page using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient; public partial class _Default : System.Web.UI.Page { // Declare local variables. int CurrentPage; int totalRecords; int totalPages; int SelectedID; string MoveState; private void HandleMoveButtons(params bool[] TorF) { btnFirst.Enabled =TorF[0]; BtnPrv.Enabled = TorF[1]; BtnNext.Enabled = TorF[2]; btnLast.Enabled= TorF[3]; } //public enum MoveState //{ // First , // Last , // Prv , // Next //} //MoveState D = MoveState.First; private void GetData() { #region Declare local data members SqlConnection connClients = new SqlConnection(); SqlCommand cmdClients = new SqlCommand(); SqlDataAdapter Da = new SqlDataAdapter(); SqlParameter parmClients; SqlDataReader drClients; DataTable dtClients = new DataTable(); DataRow drClient; #endregion Declare local data members #region Build and bind the data source // Define the DataTable. dtClients.Columns.Add("BookChapter_ID", System.Type.GetType("System.Int32")); dtClients.Columns.Add("Book_ID", System.Type.GetType("System.Int32")); dtClients.Columns.Add("ChapterTitle", System.Type.GetType("System.String")); // Create a connection to the database. try { // Connect using the connection string in the web.config. connClients.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Mubark2005ConnectionString"].ConnectionString.ToString(); connClients.Open(); // Configure the command object. //Test_GetClientsByPage cmdClients.CommandText = "Test_GetClientsByPage"; cmdClients.CommandType = CommandType.StoredProcedure; cmdClients.Connection = connClients; parmClients = new SqlParameter("@MoveState", SqlDbType.NVarChar); parmClients.Direction = ParameterDirection.Input; parmClients.Value = MoveState; //MoveState D = MoveState.Next; cmdClients.Parameters.Add(parmClients); parmClients = new SqlParameter("@SelectedID", SqlDbType.Int); parmClients.Direction = ParameterDirection.Input; if (!Page.IsPostBack) { parmClients.Value = 1; } else { //parmClients.Value = dgClients.Rows[4].Cells[0].Text; //SelectedID parmClients.Value = SelectedID; } cmdClients.Parameters.Add(parmClients); // Create the total rows parameter. parmClients = new SqlParameter("@TotalRecords", SqlDbType.Int); parmClients.Direction = ParameterDirection.Output; cmdClients.Parameters.Add(parmClients); // Process the command. // It should return to us the client rows into a DataReader. // There will also be an output parameter of the total number of clients in the db. // We need to close the DataReader prior to retrieving the output parameter. //Da.SelectCommand = cmdClients; //Da.Fill(dtClients); drClients = cmdClients.ExecuteReader(); //Iterate through the DataReader. while (drClients.Read()) { // Create a new DataRow to populate. drClient = dtClients.NewRow(); // Populate the DataRow. drClient["BookChapter_ID"] = drClients["BookChapter_ID"]; drClient["Book_ID"] = drClients["Book_ID"]; drClient["ChapterTitle"] = drClients["ChapterTitle"]; // Add the DataRow. dtClients.Rows.Add(drClient); } //Close the DataReader. drClients.Close(); // Retrieve the output parameter. totalRecords = (int)cmdClients.Parameters["@TotalRecords"].Value; // Bind the DataGrid. dgClients.DataSource = dtClients; dgClients.DataBind(); // Configure the footer. //lblCurrentPage.Text = dgClients.PageIndex.ToString(); if ((totalRecords % 5) == 0) { totalPages = totalRecords / 5; } else { totalPages = (totalRecords / 5) + 1; } //Hndel MoveButtons ================= //HandleMoveButtons(false, false, true, true); switch (MoveState) { //case "First": // HandleMoveButtons(false, false, true, true); // break; case "Last": HandleMoveButtons(true, true, false, false); dgClients.PageIndex = totalPages; break; case "Next": HandleMoveButtons(true, true, true, true); break; case "Prv": HandleMoveButtons(true, true, true, true); break; } if (dgClients.PageIndex == 1) { HandleMoveButtons(false, false, true, true); } if (totalPages == dgClients.PageIndex) { HandleMoveButtons(true, true, false, false); } //=================================== LblCount.Text = "( Page Num " + dgClients.PageIndex + " of " + totalPages.ToString() + ")"; } catch (Exception ex) { // Nothing here for now. } finally { // Close and dispose of the database connection. cmdClients.Dispose(); connClients.Close(); connClients.Dispose(); } #endregion Build and bind the data source } protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { MoveState = "First"; dgClients.PageIndex = 1; CurrentPage = 1; GetData(); } } protected void BtnNext_Click(object sender, EventArgs e) { dgClients.PageIndex += 1; SelectedID = int.Parse(dgClients.Rows[4].Cells[0].Text); MoveState = "Next"; GetData(); } protected void btnFirst_Click(object sender, EventArgs e) { dgClients.PageIndex = 1; MoveState = "First"; GetData(); } protected void btnLast_Click(object sender, EventArgs e) { //dgClients.PageIndex = totalPages; SelectedID = int.Parse(dgClients.Rows[4].Cells[0].Text); MoveState = "Last"; GetData(); } protected void BtnPrv_Click(object sender, EventArgs e) { dgClients.PageIndex -= 1; //Previous SelectedID = int.Parse(dgClients.Rows[0].Cells[0].Text); MoveState = "Prv"; GetData(); //GetData(); } } |
|||
|
|
Advanced Member Egypt تاريخ الاشتراك: 11/07/2006 عدد الردود: 166 حالة الإيصال: غير متصل |
You can also consider this solution
---------------------------------------- ٌٌRegards, Anwer Matter |
|||
|
| [مشاهدة إصدار الطباعة] [موضوع جديد] |