2007-07-24 Igor Zelmanovich <igorz@mainsoft.com>
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / DataControlField.cs
index 1de3cc852f83264cad88576e087288b8fc8711d4..93e0fbc5653a04c4130b2b8eeac7552ebb888467 100644 (file)
@@ -76,7 +76,7 @@ namespace System.Web.UI.WebControls {
                {
                        this.sortingEnabled = sortingEnabled;
                        this.control = control;
-                       return true;
+                       return false;
                }
 
                public virtual void InitializeCell (DataControlFieldCell cell,
@@ -84,15 +84,19 @@ namespace System.Web.UI.WebControls {
                {
                        if (cellType == DataControlCellType.Header)
                        {
-                               if (HeaderText.Length > 0 || HeaderImageUrl.Length > 0) {
-                                       if (sortingEnabled && SortExpression.Length > 0)
-                                               cell.Controls.Add (new DataControlButton (control, HeaderText, HeaderImageUrl, DataControlCommands.SortCommandName, SortExpression, true));
-                                       else
-                                               cell.Controls.Add (new DataControlButton (control, HeaderText, HeaderImageUrl, string.Empty, string.Empty, true));
+                               if (HeaderText.Length > 0 && sortingEnabled && SortExpression.Length > 0)
+                                       cell.Controls.Add ((Control) DataControlButton.CreateButton (String.IsNullOrEmpty (HeaderImageUrl) ? ButtonType.Link : ButtonType.Image, control, HeaderText, HeaderImageUrl, DataControlCommands.SortCommandName, SortExpression, true));
+                               else if (HeaderImageUrl.Length > 0) {
+                                       Image image = new Image ();
+                                       image.ImageUrl = HeaderImageUrl;
+                                       cell.Controls.Add (image);
                                }
+                               else
+                                       cell.Text = HeaderText.Length > 0 ? HeaderText : "&nbsp;";
                        }
                        else if (cellType == DataControlCellType.Footer) {
-                               cell.Text = FooterText;
+                               string footerText = FooterText;
+                               cell.Text = (footerText.Length > 0) ? footerText : "&nbsp;";
                        }
                }
                
@@ -136,13 +140,13 @@ namespace System.Web.UI.WebControls {
                        viewState.LoadViewState (states[0]);
                        
                        if (states[1] != null)
-                               ((IStateManager)controlStyle).LoadViewState (states[1]);
+                               ((IStateManager)ControlStyle).LoadViewState (states[1]);
                        if (states[2] != null)
-                               ((IStateManager)footerStyle).LoadViewState (states[2]);
+                               ((IStateManager)FooterStyle).LoadViewState (states[2]);
                        if (states[3] != null)
-                               ((IStateManager)headerStyle).LoadViewState (states[3]);
+                               ((IStateManager)HeaderStyle).LoadViewState (states[3]);
                        if (states[4] != null)
-                               ((IStateManager)itemStyle).LoadViewState (states[4]);
+                               ((IStateManager)ItemStyle).LoadViewState (states[4]);
                }
 
                protected virtual object SaveViewState()
@@ -200,6 +204,14 @@ namespace System.Web.UI.WebControls {
                        return new System.NotSupportedException ("The property '" + propName + "' is not supported in " + GetType().Name); 
                }
 
+               internal bool ControlStyleCreated { get { return controlStyle != null; } }
+               
+               internal bool HeaderStyleCreated { get { return headerStyle != null; } }
+               
+               internal bool FooterStyleCreated { get { return footerStyle != null; } }
+               
+               internal bool ItemStyleCreated { get { return itemStyle != null; } }
+
                [MonoTODO ("Render this")]
                [DefaultValueAttribute ("")]
                [LocalizableAttribute (true)]
@@ -223,7 +235,7 @@ namespace System.Web.UI.WebControls {
                [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
                [DefaultValueAttribute (null)]
                [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
-               public virtual Style ControlStyle {
+               public Style ControlStyle {
                        get {
                                if (controlStyle == null) {
                                        controlStyle = new Style ();
@@ -242,7 +254,7 @@ namespace System.Web.UI.WebControls {
                [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
                [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
                [WebCategoryAttribute ("Styles")]
-               public virtual TableItemStyle FooterStyle {
+               public TableItemStyle FooterStyle {
                        get {
                                if (footerStyle == null) {
                                        footerStyle = new TableItemStyle ();
@@ -286,7 +298,7 @@ namespace System.Web.UI.WebControls {
                [WebCategoryAttribute ("Styles")]
                [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
                [DefaultValueAttribute (null)]
-               public virtual TableItemStyle HeaderStyle {
+               public TableItemStyle HeaderStyle {
                        get {
                                if (headerStyle == null) {
                                        headerStyle = new TableItemStyle ();
@@ -328,7 +340,7 @@ namespace System.Web.UI.WebControls {
                [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
                [WebCategoryAttribute ("Styles")]
                [DefaultValueAttribute (null)]
-               public virtual TableItemStyle ItemStyle {
+               public TableItemStyle ItemStyle {
                        get {
                                if (itemStyle == null) {
                                        itemStyle = new TableItemStyle ();
@@ -397,6 +409,13 @@ namespace System.Web.UI.WebControls {
                }               
 
                internal event EventHandler FieldChanged;
+
+               public override string ToString ()
+               {
+                       if (string.IsNullOrEmpty (HeaderText))
+                               return base.ToString ();
+                       return HeaderText;
+               }
        }
 }
 #endif