Răsfoiți Sursa

* GridView.cs: always create Header/Fotter rows, but render only when
ShowHeader/Footer is true. Compute Header/Footer rows from rows
collection.
* CheckBoxField.cs: add override to ApplyFormatInEditMode,
add ToolTip and Text to the created CheckBox,
wrap exception thrown in OnDataBindField in httpException.

svn path=/trunk/mcs/; revision=62378

Konstantin Triger 19 ani în urmă
părinte
comite
ed0ed68f3e

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

@@ -1,3 +1,12 @@
+2006-07-06	Konstantin Triger <[email protected]>
+
+        * GridView.cs: always create Header/Fotter rows, but render only when
+        	ShowHeader/Footer is true. Compute Header/Footer rows from rows
+        	collection.
+        * CheckBoxField.cs: add override to ApplyFormatInEditMode,
+        	add ToolTip and Text to the created CheckBox,
+        	wrap exception thrown in OnDataBindField in httpException.
+
 2006-07-06	Konstantin Triger <[email protected]>
 
         * DataControlField.cs,BoundField.cs: bug fixes found by BoundFieldTest.

+ 39 - 21
mcs/class/System.Web/System.Web.UI.WebControls/CheckBoxField.cs

@@ -41,33 +41,41 @@ namespace System.Web.UI.WebControls {
 	[AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
 	public class CheckBoxField : BoundField
 	{
-	    [EditorBrowsableAttribute (EditorBrowsableState.Never)]
-	    [BrowsableAttribute (false)]
-	    [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
+		[EditorBrowsableAttribute (EditorBrowsableState.Never)]
+		[BrowsableAttribute (false)]
+		[DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
+		public override bool ApplyFormatInEditMode {
+			get { throw GetNotSupportedPropException ("ApplyFormatInEditMode"); }
+			set { throw GetNotSupportedPropException ("ApplyFormatInEditMode"); }
+		}
+
+	    [EditorBrowsableAttribute (EditorBrowsableState.Never)]
+	    [BrowsableAttribute (false)]
+	    [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
 		public override bool ConvertEmptyStringToNull {
 			get { throw GetNotSupportedPropException ("ConvertEmptyStringToNull"); } 
 			set { throw GetNotSupportedPropException ("ConvertEmptyStringToNull"); } 
 		}
 		
-	    [EditorBrowsableAttribute (EditorBrowsableState.Never)]
-	    [BrowsableAttribute (false)]
-	    [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
+	    [EditorBrowsableAttribute (EditorBrowsableState.Never)]
+	    [BrowsableAttribute (false)]
+	    [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
 		public override string DataFormatString {
 			get { throw GetNotSupportedPropException ("DataFormatString"); } 
 			set { throw GetNotSupportedPropException ("DataFormatString"); } 
 		}
 		
-	    [EditorBrowsableAttribute (EditorBrowsableState.Never)]
-	    [BrowsableAttribute (false)]
-	    [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
+	    [EditorBrowsableAttribute (EditorBrowsableState.Never)]
+	    [BrowsableAttribute (false)]
+	    [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
 		public override bool HtmlEncode {
 			get { throw GetNotSupportedPropException ("HtmlEncode"); } 
 			set { throw GetNotSupportedPropException ("HtmlEncode"); } 
 		}
 		
-	    [EditorBrowsableAttribute (EditorBrowsableState.Never)]
-	    [BrowsableAttribute (false)]
-	    [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
+	    [EditorBrowsableAttribute (EditorBrowsableState.Never)]
+	    [BrowsableAttribute (false)]
+	    [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
 		public override string NullDisplayText {
 			get { throw GetNotSupportedPropException ("NullDisplayText"); } 
 			set { throw GetNotSupportedPropException ("NullDisplayText"); } 
@@ -94,6 +102,8 @@ namespace System.Web.UI.WebControls {
 			bool editable = (rowState & (DataControlRowState.Edit | DataControlRowState.Insert)) != 0;
 			CheckBox box = new CheckBox ();
 			box.Enabled = editable && !ReadOnly;
+			box.ToolTip = HeaderText;
+			box.Text = Text;
 			cell.Controls.Add (box);
 		}
 		
@@ -106,16 +116,24 @@ namespace System.Web.UI.WebControls {
 		
 		protected override void OnDataBindField (object sender, EventArgs e)
 		{
-			DataControlFieldCell cell = (DataControlFieldCell) sender;
-			CheckBox box = (CheckBox) cell.Controls [0];
-			object val = GetValue (cell.BindingContainer);
-			if (val != null) {
-				box.Checked = (bool)val;
-				if (!box.Visible)
-					box.Visible = true;
+			try {
+				DataControlFieldCell cell = (DataControlFieldCell) sender;
+				CheckBox box = (CheckBox) cell.Controls [0];
+				object val = GetValue (cell.BindingContainer);
+				if (val != null) {
+					box.Checked = (bool) val;
+					if (!box.Visible)
+						box.Visible = true;
+				}
+				else
+					box.Visible = false;
+			}
+			catch (HttpException) {
+				throw;
+			}
+			catch (Exception ex) {
+				throw new HttpException (ex.Message, ex);
 			}
-			else
-				box.Visible = false;
 		}
 		
 		protected override object GetDesignTimeValue ()

+ 38 - 18
mcs/class/System.Web/System.Web.UI.WebControls/GridView.cs

@@ -50,8 +50,6 @@ namespace System.Web.UI.WebControls
 	{
 		Table table;
 		GridViewRowCollection rows;
-		GridViewRow headerRow;
-		GridViewRow footerRow;
 		GridViewRow bottomPagerRow;
 		GridViewRow topPagerRow;
 		
@@ -616,9 +614,21 @@ namespace System.Web.UI.WebControls
 		[BrowsableAttribute (false)]
 		public virtual GridViewRow FooterRow {
 			get {
-				if (footerRow == null)
-					footerRow = CreateRow (0, 0, DataControlRowType.Footer, DataControlRowState.Normal);
-				return footerRow;
+				if (table != null) {
+					for (int index = table.Rows.Count - 1; index >= 0; index--) {
+						GridViewRow row = (GridViewRow) table.Rows [index];
+						switch (row.RowType) {
+						case DataControlRowType.Separator:
+						case DataControlRowType.Pager:
+							continue;
+						case DataControlRowType.Footer:
+							return row;
+						default:
+							break;
+						}
+					}
+				}
+				return null;
 			}
 		}
 	
@@ -655,9 +665,21 @@ namespace System.Web.UI.WebControls
 		[BrowsableAttribute (false)]
 		public virtual GridViewRow HeaderRow {
 			get {
-				if (headerRow == null)
-					headerRow = CreateRow (0, 0, DataControlRowType.Header, DataControlRowState.Normal);
-				return headerRow;
+				if (table != null) {
+					for (int index = 0, total = table.Rows.Count; index < total; index++) {
+						GridViewRow row = (GridViewRow) table.Rows [index];
+						switch (row.RowType) {
+						case DataControlRowType.Separator:
+						case DataControlRowType.Pager:
+							continue;
+						case DataControlRowType.Header:
+							return row;
+						default:
+							break;
+						}
+					}
+				}
+				return null;
 			}
 		}
 	
@@ -1141,11 +1163,9 @@ namespace System.Web.UI.WebControls
 				table.Rows.Add (topPagerRow);
 			}
 
-			if (ShowHeader) {
-				headerRow = CreateRow (0, 0, DataControlRowType.Header, DataControlRowState.Normal);
-				table.Rows.Add (headerRow);
-				InitializeRow (headerRow, fields);
-			}
+			GridViewRow headerRow = CreateRow (0, 0, DataControlRowType.Header, DataControlRowState.Normal);
+			table.Rows.Add (headerRow);
+			InitializeRow (headerRow, fields);
 			
 			foreach (object obj in dataSource) {
 				DataControlRowState rstate = GetRowState (list.Count);
@@ -1173,11 +1193,9 @@ namespace System.Web.UI.WebControls
 			if (list.Count == 0)
 				table.Rows.Add (CreateEmptyrRow (fields.Length));
 
-			if (ShowFooter) {
-				footerRow = CreateRow (0, 0, DataControlRowType.Footer, DataControlRowState.Normal);
-				table.Rows.Add (footerRow);
-				InitializeRow (footerRow, fields);
-			}
+			GridViewRow footerRow = CreateRow (0, 0, DataControlRowType.Footer, DataControlRowState.Normal);
+			table.Rows.Add (footerRow);
+			InitializeRow (footerRow, fields);
 
 			if (showPager && PagerSettings.Position == PagerPosition.Bottom || PagerSettings.Position == PagerPosition.TopAndBottom) {
 				bottomPagerRow = CreatePagerRow (fields.Length, dataSource);
@@ -1840,9 +1858,11 @@ namespace System.Web.UI.WebControls
 			{
 				switch (row.RowType) {
 				case DataControlRowType.Header:
+					if (!ShowHeader) continue;
 					if (headerStyle != null)headerStyle.AddAttributesToRender (writer, row);
 					break;
 				case DataControlRowType.Footer:
+					if (!ShowFooter) continue;
 					if (footerStyle != null) footerStyle.AddAttributesToRender (writer, row);
 					break;
 				case DataControlRowType.Pager:

+ 1 - 6
mcs/class/System.Web/Test/System.Web.UI.WebControls/CheckBoxFieldTest.cs

@@ -186,7 +186,6 @@ namespace MonoTests.System.Web.UI.WebControls
 		}
 
 		[Test]
-		[Category ("NotWorking")]
 		public void CheckBoxField_InitializeDataCell ()
 		{
 			PokerCheckBoxField field = new PokerCheckBoxField ();
@@ -208,7 +207,6 @@ namespace MonoTests.System.Web.UI.WebControls
 		}
 
 		[Test]
-		[Category ("NotWorking")]
 		public void CheckBoxField_OnDataBindField ()
 		{
 			Page page = new Page ();
@@ -227,7 +225,6 @@ namespace MonoTests.System.Web.UI.WebControls
 		}
 
 		[Test]
-		[Category ("NotWorking")]
 		[ExpectedException (typeof (HttpException))]
 		public void CheckBoxField_OnDataBindFieldException ()
 		{
@@ -245,7 +242,6 @@ namespace MonoTests.System.Web.UI.WebControls
 		}
 
 		[Test]
-		[Category ("NotWorking")]
 		[ExpectedException(typeof(NotSupportedException))]
 		public void CheckBoxField_GetApplyFormatInEditModeExeption ()
 		{
@@ -254,7 +250,6 @@ namespace MonoTests.System.Web.UI.WebControls
 		}
 
 		[Test]
-		[Category ("NotWorking")]
 		[ExpectedException (typeof (NotSupportedException))]
 		public void CheckBoxField_SetApplyFormatInEditModeExeption ()
 		{
@@ -366,4 +361,4 @@ namespace MonoTests.System.Web.UI.WebControls
 		}
 	}
 }
-#endif
+#endif