* GridView.cs: always create Header/Fotter rows, but render only when
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / GridView.cs
index dc92f83c7c285b813951392eebfd9da1f4995885..d8be5cc51c8ccd16bb0554c09dc79880a2ad2e9d 100644 (file)
@@ -40,17 +40,16 @@ using System.Reflection;
 
 namespace System.Web.UI.WebControls
 {
+       [SupportsEventValidation]
        [DesignerAttribute ("System.Web.UI.Design.WebControls.GridViewDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
        [ControlValuePropertyAttribute ("SelectedValue")]
        [DefaultEventAttribute ("SelectedIndexChanged")]
        [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
        [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
-       public class GridView: CompositeDataBoundControl, ICallbackEventHandler, ICallbackContainer
+       public class GridView: CompositeDataBoundControl, ICallbackEventHandler, ICallbackContainer, IPostBackEventHandler, IPostBackContainer
        {
                Table table;
                GridViewRowCollection rows;
-               GridViewRow headerRow;
-               GridViewRow footerRow;
                GridViewRow bottomPagerRow;
                GridViewRow topPagerRow;
                
@@ -306,7 +305,7 @@ namespace System.Web.UI.WebControls
                
                [WebCategoryAttribute ("Paging")]
                [DefaultValueAttribute (false)]
-               public bool AllowPaging {
+               public virtual bool AllowPaging {
                        get {
                                object ob = ViewState ["AllowPaging"];
                                if (ob != null) return (bool) ob;
@@ -320,7 +319,7 @@ namespace System.Web.UI.WebControls
                
                [WebCategoryAttribute ("Behavior")]
                [DefaultValueAttribute (false)]
-               public bool AllowSorting {
+               public virtual bool AllowSorting {
                        get {
                                object ob = ViewState ["AllowSorting"];
                                if (ob != null) return (bool) ob;
@@ -332,11 +331,11 @@ namespace System.Web.UI.WebControls
                        }
                }
                
-           [WebCategoryAttribute ("Styles")]
+               [WebCategoryAttribute ("Styles")]
                [PersistenceMode (PersistenceMode.InnerProperty)]
                [NotifyParentProperty (true)]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
-               public virtual TableItemStyle AlternatingRowStyle {
+               public TableItemStyle AlternatingRowStyle {
                        get {
                                if (alternatingRowStyle == null) {
                                        alternatingRowStyle = new TableItemStyle ();
@@ -431,7 +430,7 @@ namespace System.Web.UI.WebControls
                [WebCategoryAttribute ("Accessibility")]
                [DefaultValueAttribute ("")]
                [LocalizableAttribute (true)]
-               public string Caption {
+               public virtual string Caption {
                        get {
                                object ob = ViewState ["Caption"];
                                if (ob != null) return (string) ob;
@@ -533,7 +532,7 @@ namespace System.Web.UI.WebControls
 
                [WebCategoryAttribute ("Misc")]
                [DefaultValueAttribute (-1)]
-               public int EditIndex {
+               public virtual int EditIndex {
                        get {
                                return editIndex;
                        }
@@ -543,11 +542,11 @@ namespace System.Web.UI.WebControls
                        }
                }
        
-           [WebCategoryAttribute ("Styles")]
+               [WebCategoryAttribute ("Styles")]
                [PersistenceMode (PersistenceMode.InnerProperty)]
                [NotifyParentProperty (true)]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
-               public virtual TableItemStyle EditRowStyle {
+               public TableItemStyle EditRowStyle {
                        get {
                                if (editRowStyle == null) {
                                        editRowStyle = new TableItemStyle ();
@@ -558,11 +557,11 @@ namespace System.Web.UI.WebControls
                        }
                }
                
-           [WebCategoryAttribute ("Styles")]
+               [WebCategoryAttribute ("Styles")]
                [PersistenceMode (PersistenceMode.InnerProperty)]
                [NotifyParentProperty (true)]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
-               public virtual TableItemStyle EmptyDataRowStyle {
+               public TableItemStyle EmptyDataRowStyle {
                        get {
                                if (emptyDataRowStyle == null) {
                                        emptyDataRowStyle = new TableItemStyle ();
@@ -574,10 +573,10 @@ namespace System.Web.UI.WebControls
                }
                
                [DefaultValue (null)]
-               [TemplateContainer (typeof(GridView), BindingDirection.OneWay)]
+               [TemplateContainer (typeof(GridViewRow), BindingDirection.OneWay)]
                [PersistenceMode (PersistenceMode.InnerProperty)]
-           [Browsable (false)]
-               public ITemplate EmptyDataTemplate {
+               [Browsable (false)]
+               public virtual ITemplate EmptyDataTemplate {
                        get { return emptyDataTemplate; }
                        set { emptyDataTemplate = value; RequireBinding (); }
                }
@@ -615,18 +614,30 @@ 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;
                        }
                }
        
-           [WebCategoryAttribute ("Styles")]
+               [WebCategoryAttribute ("Styles")]
                [PersistenceMode (PersistenceMode.InnerProperty)]
                [NotifyParentProperty (true)]
                [DefaultValue (null)]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
-               public virtual TableItemStyle FooterStyle {
+               public TableItemStyle FooterStyle {
                        get {
                                if (footerStyle == null) {
                                        footerStyle = new TableItemStyle ();
@@ -654,18 +665,30 @@ 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;
                        }
                }
        
-           [WebCategoryAttribute ("Styles")]
+               [WebCategoryAttribute ("Styles")]
                [PersistenceMode (PersistenceMode.InnerProperty)]
                [NotifyParentProperty (true)]
                [DefaultValue (null)]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
-               public virtual TableItemStyle HeaderStyle {
+               public TableItemStyle HeaderStyle {
                        get {
                                if (headerStyle == null) {
                                        headerStyle = new TableItemStyle ();
@@ -692,7 +715,7 @@ namespace System.Web.UI.WebControls
 
                [BrowsableAttribute (false)]
                [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
-               public int PageCount {
+               public virtual int PageCount {
                        get {
                                if (pageCount != -1) return pageCount;
                                EnsureDataBound ();
@@ -703,7 +726,7 @@ namespace System.Web.UI.WebControls
                [WebCategoryAttribute ("Paging")]
                [BrowsableAttribute (true)]
                [DefaultValueAttribute (0)]
-               public int PageIndex {
+               public virtual int PageIndex {
                        get {
                                return pageIndex;
                        }
@@ -715,7 +738,7 @@ namespace System.Web.UI.WebControls
        
                [DefaultValueAttribute (10)]
                [WebCategoryAttribute ("Paging")]
-               public int PageSize {
+               public virtual int PageSize {
                        get {
                                object ob = ViewState ["PageSize"];
                                if (ob != null) return (int) ob;
@@ -731,7 +754,7 @@ namespace System.Web.UI.WebControls
                [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
                [NotifyParentPropertyAttribute (true)]
                [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
-               public PagerSettings PagerSettings {
+               public virtual PagerSettings PagerSettings {
                        get {
                                if (pagerSettings == null) {
                                        pagerSettings = new PagerSettings (this);
@@ -742,11 +765,11 @@ namespace System.Web.UI.WebControls
                        }
                }
        
-           [WebCategoryAttribute ("Styles")]
+               [WebCategoryAttribute ("Styles")]
                [PersistenceMode (PersistenceMode.InnerProperty)]
                [NotifyParentProperty (true)]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
-               public virtual TableItemStyle PagerStyle {
+               public TableItemStyle PagerStyle {
                        get {
                                if (pagerStyle == null) {
                                        pagerStyle = new TableItemStyle ();
@@ -762,15 +785,15 @@ namespace System.Web.UI.WebControls
                /* DataControlPagerCell isnt specified in the docs */
                //[TemplateContainer (typeof(DataControlPagerCell), BindingDirection.OneWay)]
                [PersistenceMode (PersistenceMode.InnerProperty)]
-           [Browsable (false)]
-               public ITemplate PagerTemplate {
+               [Browsable (false)]
+               public virtual ITemplate PagerTemplate {
                        get { return pagerTemplate; }
                        set { pagerTemplate = value; RequireBinding (); }
                }
                
                [DefaultValueAttribute ("")]
                [WebCategoryAttribute ("Accessibility")]
-//             [TypeConverterAttribute (typeof(System.Web.UI.Design.DataColumnSelectionConverter)]
+               //              [TypeConverterAttribute (typeof(System.Web.UI.Design.DataColumnSelectionConverter)]
                public virtual string RowHeaderColumn {
                        get {
                                object ob = ViewState ["RowHeaderColumn"];
@@ -792,11 +815,11 @@ namespace System.Web.UI.WebControls
                        }
                }
                
-           [WebCategoryAttribute ("Styles")]
+               [WebCategoryAttribute ("Styles")]
                [PersistenceMode (PersistenceMode.InnerProperty)]
                [NotifyParentProperty (true)]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
-               public virtual TableItemStyle RowStyle {
+               public TableItemStyle RowStyle {
                        get {
                                if (rowStyle == null) {
                                        rowStyle = new TableItemStyle ();
@@ -820,18 +843,18 @@ namespace System.Web.UI.WebControls
                
                [BindableAttribute (true)]
                [DefaultValueAttribute (-1)]
-               public int SelectedIndex {
+               public virtual int SelectedIndex {
                        get {
                                return selectedIndex;
                        }
                        set {
-                               if (selectedIndex >= 0 && selectedIndex < Rows.Count) {
+                               if (Rows != null && selectedIndex >= 0 && selectedIndex < Rows.Count) {
                                        int oldIndex = selectedIndex;
                                        selectedIndex = -1;
                                        Rows [oldIndex].RowState = GetRowState (oldIndex);
                                }
                                selectedIndex = value;
-                               if (selectedIndex >= 0 && selectedIndex < Rows.Count) {
+                               if (Rows != null && selectedIndex >= 0 && selectedIndex < Rows.Count) {
                                        Rows [selectedIndex].RowState = GetRowState (selectedIndex);
                                }
                        }
@@ -848,11 +871,11 @@ namespace System.Web.UI.WebControls
                        }
                }
                
-           [WebCategoryAttribute ("Styles")]
+               [WebCategoryAttribute ("Styles")]
                [PersistenceMode (PersistenceMode.InnerProperty)]
                [NotifyParentProperty (true)]
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
-               public virtual TableItemStyle SelectedRowStyle {
+               public TableItemStyle SelectedRowStyle {
                        get {
                                if (selectedRowStyle == null) {
                                        selectedRowStyle = new TableItemStyle ();
@@ -864,7 +887,7 @@ namespace System.Web.UI.WebControls
                }
                
                [BrowsableAttribute (false)]
-               public virtual object SelectedValue {
+               public object SelectedValue {
                        get {
                                if (SelectedDataKey != null)
                                        return SelectedDataKey.Value;
@@ -994,9 +1017,9 @@ namespace System.Web.UI.WebControls
                                object fitem = null;
                                prop_type = null;
                                PropertyInfo prop_item =  source.DataSource.GetType().GetProperty("Item",
-                                                 BindingFlags.Instance | BindingFlags.Static |
-                                                 BindingFlags.Public, null, null,
-                                                 new Type[] { typeof(int) }, null);
+                                                                                                 BindingFlags.Instance | BindingFlags.Static |
+                                                                                                 BindingFlags.Public, null, null,
+                                                                                                 new Type[] { typeof(int) }, null);
                                
                                if (prop_item != null) {
                                        prop_type = prop_item.PropertyType;
@@ -1140,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);
@@ -1154,7 +1175,7 @@ namespace System.Web.UI.WebControls
                                table.Rows.Add (row);
                                InitializeRow (row, fields);
                                if (dataBinding) {
-//                                     row.DataBind ();
+                                       row.DataBind ();
                                        OnRowDataBound (new GridViewRowEventArgs (row));
                                        if (EditIndex == row.RowIndex)
                                                oldEditValues = new DataKey (GetRowValues (row, false, true));
@@ -1172,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);
@@ -1185,9 +1204,6 @@ namespace System.Web.UI.WebControls
 
                        rows = new GridViewRowCollection (list);
                        keys = new DataKeyArray (keyList);
-                       
-                       if (dataBinding)
-                               DataBind (false);
 
                        return dataSource.DataSourceCount;
                }
@@ -1247,16 +1263,16 @@ namespace System.Web.UI.WebControls
                        bool accessibleHeader = false;
 
                        switch (row.RowType) {
-                               case DataControlRowType.Header:
-                                       ctype = DataControlCellType.Header; 
-                                       accessibleHeader = UseAccessibleHeader;
-                                       break;
-                               case DataControlRowType.Footer:
-                                       ctype = DataControlCellType.Footer;
-                                       break;
-                               default:
-                                       ctype = DataControlCellType.DataCell;
-                                       break;
+                       case DataControlRowType.Header:
+                               ctype = DataControlCellType.Header; 
+                               accessibleHeader = UseAccessibleHeader;
+                               break;
+                       case DataControlRowType.Footer:
+                               ctype = DataControlCellType.Footer;
+                               break;
+                       default:
+                               ctype = DataControlCellType.DataCell;
+                               break;
                        }
                        
                        for (int n=0; n<fields.Length; n++) {
@@ -1378,11 +1394,22 @@ namespace System.Web.UI.WebControls
                        GridViewCommandEventArgs args = e as GridViewCommandEventArgs;
                        if (args != null) {
                                OnRowCommand (args);
-                               ProcessEvent (args.CommandName, args.CommandArgument as string);
+                               string param = args.CommandArgument as string;
+                               if (param == null || param.Length == 0) {
+                                       GridViewRow row = args.Row;
+                                       if (row != null)
+                                               param = row.RowIndex.ToString();
+                               }
+                               ProcessEvent (args.CommandName, param);
                        }
                        return base.OnBubbleEvent (source, e);
                }
                
+               void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
+               {
+                       RaisePostBackEvent (eventArgument);
+               }
+
                // This is prolly obsolete
                protected virtual void RaisePostBackEvent (string eventArgument)
                {
@@ -1397,69 +1424,69 @@ namespace System.Web.UI.WebControls
                {
                        switch (eventName)
                        {
-                               case DataControlCommands.PageCommandName:
-                                       int newIndex = -1;
-                                       switch (param) {
-                                               case DataControlCommands.FirstPageCommandArgument:
-                                                       newIndex = 0;
-                                                       break;
-                                               case DataControlCommands.LastPageCommandArgument:
-                                                       newIndex = PageCount - 1;
-                                                       break;
-                                               case DataControlCommands.NextPageCommandArgument:
-                                                       if (PageIndex < PageCount - 1) newIndex = PageIndex + 1;
-                                                       break;
-                                               case DataControlCommands.PreviousPageCommandArgument:
-                                                       if (PageIndex > 0) newIndex = PageIndex - 1;
-                                                       break;
-                                               default:
-                                                       newIndex = int.Parse (param) - 1;
-                                                       break;
-                                       }
-                                       ShowPage (newIndex);
-                                       break;
-                                       
+                       case DataControlCommands.PageCommandName:
+                               int newIndex = -1;
+                               switch (param) {
                                case DataControlCommands.FirstPageCommandArgument:
-                                       ShowPage (0);
+                                       newIndex = 0;
                                        break;
-
                                case DataControlCommands.LastPageCommandArgument:
-                                       ShowPage (PageCount - 1);
+                                       newIndex = PageCount - 1;
                                        break;
-                                       
                                case DataControlCommands.NextPageCommandArgument:
-                                       if (PageIndex < PageCount - 1)
-                                               ShowPage (PageIndex + 1);
+                                       if (PageIndex < PageCount - 1) newIndex = PageIndex + 1;
                                        break;
-
                                case DataControlCommands.PreviousPageCommandArgument:
-                                       if (PageIndex > 0)
-                                               ShowPage (PageIndex - 1);
+                                       if (PageIndex > 0) newIndex = PageIndex - 1;
                                        break;
-                                       
-                               case DataControlCommands.SelectCommandName:
-                                       SelectRow (int.Parse (param));
+                               default:
+                                       newIndex = int.Parse (param) - 1;
                                        break;
+                               }
+                               ShowPage (newIndex);
+                               break;
                                        
-                               case DataControlCommands.EditCommandName:
-                                       EditRow (int.Parse (param));
-                                       break;
+                       case DataControlCommands.FirstPageCommandArgument:
+                               ShowPage (0);
+                               break;
+
+                       case DataControlCommands.LastPageCommandArgument:
+                               ShowPage (PageCount - 1);
+                               break;
                                        
-                               case DataControlCommands.UpdateCommandName:
-                                       UpdateRow (EditIndex, true);
-                                       break;
+                       case DataControlCommands.NextPageCommandArgument:
+                               if (PageIndex < PageCount - 1)
+                                       ShowPage (PageIndex + 1);
+                               break;
+
+                       case DataControlCommands.PreviousPageCommandArgument:
+                               if (PageIndex > 0)
+                                       ShowPage (PageIndex - 1);
+                               break;
                                        
-                               case DataControlCommands.CancelCommandName:
-                                       CancelEdit ();
-                                       break;
+                       case DataControlCommands.SelectCommandName:
+                               SelectRow (int.Parse (param));
+                               break;
                                        
-                               case DataControlCommands.DeleteCommandName:
-                                       DeleteRow (int.Parse (param));
-                                       break;
+                       case DataControlCommands.EditCommandName:
+                               EditRow (int.Parse (param));
+                               break;
                                        
-                               case DataControlCommands.SortCommandName:
-                                       Sort (param);
-                                       break;
+                       case DataControlCommands.UpdateCommandName:
+                               UpdateRow (EditIndex, true);
+                               break;
+                                       
+                       case DataControlCommands.CancelCommandName:
+                               CancelEdit ();
+                               break;
+                                       
+                       case DataControlCommands.DeleteCommandName:
+                               DeleteRow (int.Parse (param));
+                               break;
+                                       
+                       case DataControlCommands.SortCommandName:
+                               Sort (param);
+                               break;
                        }
                }
                
@@ -1477,7 +1504,7 @@ namespace System.Web.UI.WebControls
                        Sort (newSortExpression, newDirection);
                }
                
-               public void Sort (string newSortExpression, SortDirection newSortDirection)
+               public virtual void Sort (string newSortExpression, SortDirection newSortDirection)
                {
                        GridViewSortEventArgs args = new GridViewSortEventArgs (newSortExpression, newSortDirection);
                        OnSorting (args);
@@ -1553,7 +1580,7 @@ namespace System.Web.UI.WebControls
                                EndRowEdit ();
                }
 
-        bool UpdateCallback (int recordsAffected, Exception exception)
+               bool UpdateCallback (int recordsAffected, Exception exception)
                {
                        GridViewUpdatedEventArgs dargs = new GridViewUpdatedEventArgs (recordsAffected, exception, currentEditRowKeys, currentEditOldValues, currentEditNewValues);
                        OnRowUpdated (dargs);
@@ -1564,7 +1591,7 @@ namespace System.Web.UI.WebControls
                        return dargs.ExceptionHandled;
                }
                
-               public void DeleteRow (int rowIndex)
+               public virtual void DeleteRow (int rowIndex)
                {
                        GridViewRow row = Rows [rowIndex];
                        currentEditRowKeys = DataKeys [rowIndex].Values;
@@ -1585,7 +1612,7 @@ namespace System.Web.UI.WebControls
                        }
                }
 
-        bool DeleteCallback (int recordsAffected, Exception exception)
+               bool DeleteCallback (int recordsAffected, Exception exception)
                {
                        GridViewDeletedEventArgs dargs = new GridViewDeletedEventArgs (recordsAffected, exception, currentEditRowKeys, currentEditNewValues);
                        OnRowDeleted (dargs);
@@ -1619,7 +1646,7 @@ namespace System.Web.UI.WebControls
                        object bstate = base.SaveControlState ();
                        return new object[] {
                                bstate, pageIndex, pageCount, selectedIndex, editIndex, sortExpression, sortDirection
-                       };
+                                       };
                }
                
                protected override void TrackViewState()
@@ -1714,12 +1741,13 @@ namespace System.Web.UI.WebControls
                        if (states[12] != null && oldEditValues != null) ((IStateManager)oldEditValues).LoadViewState (states[12]);
                }
                
-               string ICallbackEventHandler.RaiseCallbackEvent (string eventArgs)
+               void ICallbackEventHandler.RaiseCallbackEvent (string eventArgs)
                {
-                       return RaiseCallbackEvent (eventArgs);
+                       RaiseCallbackEvent (eventArgs);
                }
                
-               protected virtual string RaiseCallbackEvent (string eventArgs)
+               string callbackResult;
+               protected virtual void RaiseCallbackEvent (string eventArgs)
                {
                        string[] clientData = eventArgs.Split ('|');
                        pageIndex = int.Parse (clientData[0]);
@@ -1735,9 +1763,19 @@ namespace System.Web.UI.WebControls
 
                        HtmlTextWriter writer = new HtmlTextWriter (sw);
                        RenderGrid (writer);
-                       return sw.ToString ();
+                       callbackResult = sw.ToString ();
                }
                
+               string ICallbackEventHandler.GetCallbackResult ()
+               {
+                       return GetCallbackResult ();
+               }
+
+               protected virtual string GetCallbackResult ()
+               {
+                       return callbackResult;
+               }
+
                string ICallbackContainer.GetCallbackScript (IButtonControl control, string argument)
                {
                        return GetCallbackScript (control, argument);
@@ -1776,7 +1814,7 @@ namespace System.Web.UI.WebControls
                                Page.ClientScript.RegisterStartupScript (typeof(TreeView), this.UniqueID, script, true);
                                
                                // Make sure the basic script infrastructure is rendered
-                       Page.ClientScript.GetCallbackEventReference (this, "null", "", "null");
+                               Page.ClientScript.GetCallbackEventReference (this, "null", "", "null");
                                Page.ClientScript.GetPostBackClientHyperlink (this, "");
                        }
                }
@@ -1795,21 +1833,21 @@ namespace System.Web.UI.WebControls
                void RenderGrid (HtmlTextWriter writer)
                {
                        switch (GridLines) {
-                               case GridLines.Horizontal:
-                                       writer.AddAttribute (HtmlTextWriterAttribute.Rules, "rows");
-                                       writer.AddAttribute (HtmlTextWriterAttribute.Border, "1");
-                                       break;
-                               case GridLines.Vertical:
-                                       writer.AddAttribute (HtmlTextWriterAttribute.Rules, "cols");
-                                       writer.AddAttribute (HtmlTextWriterAttribute.Border, "1");
-                                       break;
-                               case GridLines.Both:
-                                       writer.AddAttribute (HtmlTextWriterAttribute.Rules, "all");
-                                       writer.AddAttribute (HtmlTextWriterAttribute.Border, "1");
-                                       break;
-                               default:
-                                       writer.AddAttribute (HtmlTextWriterAttribute.Border, "0");
-                                       break;
+                       case GridLines.Horizontal:
+                               writer.AddAttribute (HtmlTextWriterAttribute.Rules, "rows");
+                               writer.AddAttribute (HtmlTextWriterAttribute.Border, "1");
+                               break;
+                       case GridLines.Vertical:
+                               writer.AddAttribute (HtmlTextWriterAttribute.Rules, "cols");
+                               writer.AddAttribute (HtmlTextWriterAttribute.Border, "1");
+                               break;
+                       case GridLines.Both:
+                               writer.AddAttribute (HtmlTextWriterAttribute.Rules, "all");
+                               writer.AddAttribute (HtmlTextWriterAttribute.Border, "1");
+                               break;
+                       default:
+                               writer.AddAttribute (HtmlTextWriterAttribute.Border, "0");
+                               break;
                        }
                        
                        writer.AddAttribute (HtmlTextWriterAttribute.Cellspacing, "0");
@@ -1819,23 +1857,26 @@ namespace System.Web.UI.WebControls
                        foreach (GridViewRow row in table.Rows)
                        {
                                switch (row.RowType) {
-                                       case DataControlRowType.Header:
-                                               if (headerStyle != null)headerStyle.AddAttributesToRender (writer, row);
-                                               break;
-                                       case DataControlRowType.Footer:
-                                               if (footerStyle != null) footerStyle.AddAttributesToRender (writer, row);
-                                               break;
-                                       case DataControlRowType.Pager:
-                                               if (pagerStyle != null) pagerStyle.AddAttributesToRender (writer, row);
-                                               break;
-                                       case DataControlRowType.EmptyDataRow:
-                                               if (emptyDataRowStyle != null) emptyDataRowStyle.AddAttributesToRender (writer, row);
-                                               break;
-                                       default:
-                                               if (rowStyle != null) rowStyle.AddAttributesToRender (writer, row);
-                                               break;
+                               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:
+                                       if (pagerStyle != null) pagerStyle.AddAttributesToRender (writer, row);
+                                       break;
+                               case DataControlRowType.EmptyDataRow:
+                                       if (emptyDataRowStyle != null) emptyDataRowStyle.AddAttributesToRender (writer, row);
+                                       break;
+                               default:
+                                       break;
                                }
 
+                               if ((row.RowState & DataControlRowState.Normal) != 0 && rowStyle != null)
+                                       rowStyle.AddAttributesToRender (writer, row);
                                if ((row.RowState & DataControlRowState.Alternate) != 0 && alternatingRowStyle != null)
                                        alternatingRowStyle.AddAttributesToRender (writer, row);
                                if ((row.RowState & DataControlRowState.Edit) != 0 && editRowStyle != null)
@@ -1850,9 +1891,9 @@ namespace System.Web.UI.WebControls
                                        if (fcell != null) {
                                                Style cellStyle = null;
                                                switch (row.RowType) {
-                                                       case DataControlRowType.Header: cellStyle = fcell.ContainingField.HeaderStyle; break;
-                                                       case DataControlRowType.Footer: cellStyle = fcell.ContainingField.FooterStyle; break;
-                                                       default: cellStyle = fcell.ContainingField.ItemStyle; break;
+                                               case DataControlRowType.Header: cellStyle = fcell.ContainingField.HeaderStyle; break;
+                                               case DataControlRowType.Footer: cellStyle = fcell.ContainingField.FooterStyle; break;
+                                               default: cellStyle = fcell.ContainingField.ItemStyle; break;
                                                }
                                                if (cellStyle != null)
                                                        cellStyle.AddAttributesToRender (writer, cell);
@@ -1863,6 +1904,12 @@ namespace System.Web.UI.WebControls
                        }
                        table.RenderEndTag (writer);
                }
+
+               [MonoTODO]
+               PostBackOptions IPostBackContainer.GetPostBackOptions (IButtonControl control)
+               {
+                       throw new NotImplementedException ();
+               }
        }
 }