* GridView.cs: always create Header/Fotter rows, but render only when
authorKonstantin Triger <kostat@mono-cvs.ximian.com>
Sun, 9 Jul 2006 13:05:20 +0000 (13:05 -0000)
committerKonstantin Triger <kostat@mono-cvs.ximian.com>
Sun, 9 Jul 2006 13:05:20 +0000 (13:05 -0000)
     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

mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
mcs/class/System.Web/System.Web.UI.WebControls/CheckBoxField.cs
mcs/class/System.Web/System.Web.UI.WebControls/GridView.cs
mcs/class/System.Web/Test/System.Web.UI.WebControls/CheckBoxFieldTest.cs

index 4bd14a2b7e113b204af20fd9d5eb97c082e31231..88374d1cdffcb844f54c6a8dad38d420ff4d4fa2 100644 (file)
@@ -1,3 +1,12 @@
+2006-07-06     Konstantin Triger <kostat@mainsoft.com>
+
+        * 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 <kostat@mainsoft.com>
 
         * DataControlField.cs,BoundField.cs: bug fixes found by BoundFieldTest.
index 5234fe4822c26b8954e373ff90ed81ebcec112c8..97dbf79d363f8da59edf789ec80f79928ffe153b 100644 (file)
@@ -41,33 +41,41 @@ namespace System.Web.UI.WebControls {
        [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
        public class CheckBoxField : BoundField
        {
-           [EditorBrowsableAttribute (EditorBrowsableState.Never)]\r
-           [BrowsableAttribute (false)]\r
-           [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]\r
+               [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)]\r
-           [BrowsableAttribute (false)]\r
-           [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]\r
+           [EditorBrowsableAttribute (EditorBrowsableState.Never)]
+           [BrowsableAttribute (false)]
+           [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
                public override string DataFormatString {
                        get { throw GetNotSupportedPropException ("DataFormatString"); } 
                        set { throw GetNotSupportedPropException ("DataFormatString"); } 
                }
                
-           [EditorBrowsableAttribute (EditorBrowsableState.Never)]\r
-           [BrowsableAttribute (false)]\r
-           [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]\r
+           [EditorBrowsableAttribute (EditorBrowsableState.Never)]
+           [BrowsableAttribute (false)]
+           [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
                public override bool HtmlEncode {
                        get { throw GetNotSupportedPropException ("HtmlEncode"); } 
                        set { throw GetNotSupportedPropException ("HtmlEncode"); } 
                }
                
-           [EditorBrowsableAttribute (EditorBrowsableState.Never)]\r
-           [BrowsableAttribute (false)]\r
-           [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]\r
+           [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 ()
index 2f70f366986e13baf6d6331bf580545d4433a3ab..d8be5cc51c8ccd16bb0554c09dc79880a2ad2e9d 100644 (file)
@@ -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:
index c1a0e57c7a9d43fcff10e64df7857324b8e87398..2ab402da6ba95a713ab38650abf9ddde2d22f7ec 100644 (file)
@@ -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
\ No newline at end of file
+#endif