Răsfoiți Sursa

2006-10-24 Igor Zelmanovich <[email protected]>

	* PagerSettings.cs: fixed: CreatePagerControl.


svn path=/trunk/mcs/; revision=66925
Igor Zelmanovich 19 ani în urmă
părinte
comite
0cae7f4fa5

+ 4 - 0
mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog

@@ -1,3 +1,7 @@
+2006-10-24 Igor Zelmanovich <[email protected]>
+
+	* PagerSettings.cs: fixed: CreatePagerControl.
+
 2006-10-24 Igor Zelmanovich <[email protected]>
 
 	* CommandField.cs: fixed: 

+ 39 - 31
mcs/class/System.Web/System.Web.UI.WebControls/PagerSettings.cs

@@ -276,43 +276,51 @@ namespace System.Web.UI.WebControls
 			TableRow row = new TableRow ();
 			table.Rows.Add (row);
 
-			if (Mode == PagerButtons.NextPrevious || Mode == PagerButtons.NextPreviousFirstLast)
-			{
-				if (currentPage > 0) {
-					if (Mode == PagerButtons.NextPreviousFirstLast)
-						row.Cells.Add (CreateCell (FirstPageText, FirstPageImageUrl, "Page", "First"));
-					row.Cells.Add (CreateCell (PreviousPageText, PreviousPageImageUrl, "Page", "Prev"));
-				}
-				if (currentPage < pageCount - 1) {
-					row.Cells.Add (CreateCell (NextPageText, NextPageImageUrl, "Page", "Next"));
-					if (Mode == PagerButtons.NextPreviousFirstLast)
-						row.Cells.Add (CreateCell (LastPageText, LastPageImageUrl, "Page", "Last"));
-				}
+			int buttonCount = (Mode == PagerButtons.Numeric || Mode == PagerButtons.NumericFirstLast) ? PageButtonCount : 1;
+			int first = buttonCount * (currentPage / buttonCount);
+			int last = first + buttonCount;
+			if (last > pageCount) {
+				last = pageCount;
+				if (last - first < buttonCount)
+					first = last - buttonCount;
+				if (first < 0)
+					first = 0;
+			}
+
+			// First button
+			if (Mode == PagerButtons.NumericFirstLast || Mode == PagerButtons.NextPreviousFirstLast) {
+				if (first > 0)
+					row.Cells.Add (CreateCell (FirstPageText, FirstPageImageUrl, "Page", "First"));
 			}
-			else if (Mode == PagerButtons.Numeric || Mode == PagerButtons.NumericFirstLast)
-			{
-				int pbc = PageButtonCount;
-				int cp = currentPage + 1;
-				int pbp = pbc <= cp ? cp / pbc : 0;
-				int first = cp < pbc ? 0 : (cp + (pbp % pbc) - (pbc + pbp)) + 1;
-				int last = first + pbc;
-				if (last >= pageCount) last = pageCount;
-				
-				if (first > 0) {
-					if (Mode == PagerButtons.NumericFirstLast)
-						row.Cells.Add (CreateCell (FirstPageText, FirstPageImageUrl, "Page", "First"));
+
+			// Prev button
+			if (Mode == PagerButtons.NextPrevious || Mode == PagerButtons.NextPreviousFirstLast) {
+				if (first > 0)
 					row.Cells.Add (CreateCell (PreviousPageText, PreviousPageImageUrl, "Page", "Prev"));
-				}
-				
+			}
+
+			// Numbers
+			if (Mode == PagerButtons.Numeric || Mode == PagerButtons.NumericFirstLast) {
+				if (first > 0)
+					row.Cells.Add (CreateCell ("...", string.Empty, "Page", first.ToString ()));
 				for (int n = first; n < last; n++)
 					row.Cells.Add (CreateCell ((n + 1).ToString (), string.Empty, (n != currentPage) ? "Page" : "", (n + 1).ToString ()));
-				
-				if (last < pageCount - 1) {
+				if (last < pageCount)
+					row.Cells.Add (CreateCell ("...", string.Empty, "Page", (last + 1).ToString ()));
+			}
+
+			// Next button
+			if (Mode == PagerButtons.NextPrevious || Mode == PagerButtons.NextPreviousFirstLast) {
+				if (last < pageCount)
 					row.Cells.Add (CreateCell (NextPageText, NextPageImageUrl, "Page", "Next"));
-					if (Mode == PagerButtons.NumericFirstLast)
-						row.Cells.Add (CreateCell (LastPageText, LastPageImageUrl, "Page", "Last"));
-				}
 			}
+
+			// Last button
+			if (Mode == PagerButtons.NumericFirstLast || Mode == PagerButtons.NextPreviousFirstLast) {
+				if (last < pageCount)
+					row.Cells.Add (CreateCell (LastPageText, LastPageImageUrl, "Page", "Last"));
+			}
+			
 			return table;
 		}
 

+ 4 - 0
mcs/class/System.Web/Test/System.Web.UI.WebControls/ChangeLog

@@ -1,3 +1,7 @@
+2006-10-24 Igor Zelmanovich <[email protected]>
+
+	* GridViewTest.cs: new test was added
+			
 2006-10-24 Igor Zelmanovich <[email protected]>
 
 	* GridViewTest.cs: removed NotWorking attributes

+ 55 - 0
mcs/class/System.Web/Test/System.Web.UI.WebControls/GridViewTest.cs

@@ -1308,6 +1308,60 @@ namespace MonoTests.System.Web.UI.WebControls
 		 	p.Form.Controls.Add (lce);
 		}
 
+		[Test]
+		[Category("NunitWeb")]
+		public void GridView_RenderAllowPaging2 () {
+			string RenderedPageHtml = new WebTest (PageInvoker.CreateOnLoad (RenderAllowPaging2)).Run ();
+			string RenderedControlHtml = HtmlDiff.GetControlFromPageHtml (RenderedPageHtml);
+			string OriginControlHtml = @"<div>
+										<table cellspacing=""0"" rules=""all"" border=""1"" style=""border-collapse:collapse;"">
+											<tr>
+												<th scope=""col"">Item</th>
+											</tr><tr>
+												<td>France</td>
+											</tr><tr>
+												<td>Italy</td>
+											</tr><tr>
+												<td><table border=""0"">
+													<tr>
+														<td><a href=""javascript:__doPostBack('ctl01','Page$1')"">1</a></td><td><span>2</span></td><td><a href=""javascript:__doPostBack('ctl01','Page$3')"">3</a></td><td><a href=""javascript:__doPostBack('ctl01','Page$4')"">4</a></td><td><a href=""javascript:__doPostBack('ctl01','Page$5')"">...</a></td><td><a href=""javascript:__doPostBack('ctl01','Page$Last')"">&gt;&gt;</a></td>
+													</tr>
+												</table></td>
+											</tr>
+										</table>
+									</div>";
+			HtmlDiff.AssertAreEqual (OriginControlHtml, RenderedControlHtml, "RenderDefault");
+		}
+
+		public static void RenderAllowPaging2 (Page p) {
+			ArrayList myds = new ArrayList ();
+			myds.Add ("Norway");
+			myds.Add ("Sweden");
+			myds.Add ("France");
+			myds.Add ("Italy");
+			myds.Add ("Norway");
+			myds.Add ("Sweden");
+			myds.Add ("France");
+			myds.Add ("Italy");
+			myds.Add ("Norway");
+			myds.Add ("Sweden");
+			myds.Add ("France");
+			myds.Add ("Italy");
+			LiteralControl lcb = new LiteralControl (HtmlDiff.BEGIN_TAG);
+			LiteralControl lce = new LiteralControl (HtmlDiff.END_TAG);
+			PokerGridView b = new PokerGridView ();
+			p.Form.Controls.Add (lcb);
+			p.Form.Controls.Add (b);
+			b.AllowPaging = true;
+			b.PageSize = 2;
+			b.PageIndex = 1;
+			b.PagerSettings.PageButtonCount = 4;
+			b.PagerSettings.Mode= PagerButtons.NumericFirstLast;
+			b.DataSource = myds;
+			b.DataBind ();
+			p.Form.Controls.Add (lce);
+		}
+
 		[Test]
 		public void GridView_RenderProperty ()
 		{
@@ -2315,3 +2369,4 @@ namespace MonoTests.System.Web.UI.WebControls
 
 
 
+