2007-01-10 Igor Zelmanovich <igorz@mainsoft.com>
authorIgor Zelmanovich <igorz@mono-cvs.ximian.com>
Wed, 10 Jan 2007 15:02:50 +0000 (15:02 -0000)
committerIgor Zelmanovich <igorz@mono-cvs.ximian.com>
Wed, 10 Jan 2007 15:02:50 +0000 (15:02 -0000)
* GridView.cs: fixed: header and footer does not appear in no items.
* CompositeDataBoundControl.cs:

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

mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
mcs/class/System.Web/System.Web.UI.WebControls/CompositeDataBoundControl.cs
mcs/class/System.Web/System.Web.UI.WebControls/GridView.cs

index 0df757b73f633662c00fb0edde6ae2c287e37dcd..913de2858e3a556f27d069b1e48902bbd7fbd5ec 100644 (file)
@@ -1,3 +1,8 @@
+2007-01-10 Igor Zelmanovich <igorz@mainsoft.com>
+
+       * GridView.cs: fixed: header and footer does not appear in no items.
+       * CompositeDataBoundControl.cs:
+
 2007-01-09 Konstantin Triger <kostat@mainsoft.com>
 
        * AdRotator.cs: Backport the fix for AdRotator AbsoluteUri to 1.1.
index f0d6160c576564e341e8be8ffe6ea3632f5add7f..0c2c6063613bb2cdc61626731778d5915bfecb59 100644 (file)
@@ -56,7 +56,7 @@ namespace System.Web.UI.WebControls
                        object itemCount = ViewState ["_ItemCount"];
                        if (itemCount != null) {
                                object [] data = new object [(int) itemCount];
-                               ViewState ["_ItemCount"] = CreateChildControls (data, false);
+                               CreateChildControls (data, false);
                        }
                        else if (RequiresDataBinding)
                                EnsureDataBound ();
index 74344c33dbbe1d0e5d08cdb3fd1ca89fdaeef895..a84a224fbc03974f3b608967fd0b00120d29d71a 100644 (file)
@@ -1234,14 +1234,8 @@ namespace System.Web.UI.WebControls
                                }
                        }
 
-                       if (dataSource.DataSourceCount == 0)
-                               return 0;
-
                        bool showPager = AllowPaging && (PageCount > 1);
                        
-                       table = CreateChildTable ();
-                       Controls.Add (table);
-                               
                        ArrayList list = new ArrayList ();
                        
                        // Creates the set of fields to show
@@ -1257,28 +1251,30 @@ namespace System.Web.UI.WebControls
                        }
 
                        // Main table creation
-                       
-                       if (showPager && PagerSettings.Position == PagerPosition.Top || PagerSettings.Position == PagerPosition.TopAndBottom) {
-                               topPagerRow = CreatePagerRow (fields.Length, dataSource);
-                               table.Rows.Add (topPagerRow);
-                               OnRowCreated (new GridViewRowEventArgs (topPagerRow));
-                       }
-
-                       GridViewRow headerRow = CreateRow (0, 0, DataControlRowType.Header, DataControlRowState.Normal);
-                       table.Rows.Add (headerRow);
-                       InitializeRow (headerRow, fields);
-                       OnRowCreated (new GridViewRowEventArgs (headerRow));
-                       if (dataBinding) {
-                               headerRow.DataBind ();
-                               OnRowDataBound (new GridViewRowEventArgs (headerRow));
-                       }
-                       
                        foreach (object obj in dataSource) {
+                               
+                               if (list.Count == 0) {
+                                       if (showPager && PagerSettings.Position == PagerPosition.Top || PagerSettings.Position == PagerPosition.TopAndBottom) {
+                                               topPagerRow = CreatePagerRow (fields.Length, dataSource);
+                                               ContainedTable.Rows.Add (topPagerRow);
+                                               OnRowCreated (new GridViewRowEventArgs (topPagerRow));
+                                       }
+
+                                       GridViewRow headerRow = CreateRow (-1, -1, DataControlRowType.Header, DataControlRowState.Normal);
+                                       ContainedTable.Rows.Add (headerRow);
+                                       InitializeRow (headerRow, fields);
+                                       OnRowCreated (new GridViewRowEventArgs (headerRow));
+                                       if (dataBinding) {
+                                               headerRow.DataBind ();
+                                               OnRowDataBound (new GridViewRowEventArgs (headerRow));
+                                       }
+                               }
+                               
                                DataControlRowState rstate = GetRowState (list.Count);
                                GridViewRow row = CreateRow (list.Count, list.Count, DataControlRowType.DataRow, rstate);
                                row.DataItem = obj;
                                list.Add (row);
-                               table.Rows.Add (row);
+                               ContainedTable.Rows.Add (row);
                                InitializeRow (row, fields);
                                OnRowCreated (new GridViewRowEventArgs (row));
                                if (dataBinding) {
@@ -1292,32 +1288,52 @@ namespace System.Web.UI.WebControls
 
                        if (list.Count == 0) {
                                GridViewRow emptyRow = CreateEmptyrRow (fields.Length);
-                               table.Rows.Add (emptyRow);
-                               OnRowCreated (new GridViewRowEventArgs (emptyRow));
-                               if (dataBinding) {
-                                       emptyRow.DataBind ();
-                                       OnRowDataBound (new GridViewRowEventArgs (emptyRow));
+                               if (emptyRow != null) {
+                                       ContainedTable.Rows.Add (emptyRow);
+                                       OnRowCreated (new GridViewRowEventArgs (emptyRow));
+                                       if (dataBinding) {
+                                               emptyRow.DataBind ();
+                                               OnRowDataBound (new GridViewRowEventArgs (emptyRow));
+                                       }
                                }
+                               return 0;
                        }
+                       else {
+                               GridViewRow footerRow = CreateRow (-1, -1, DataControlRowType.Footer, DataControlRowState.Normal);
+                               ContainedTable.Rows.Add (footerRow);
+                               InitializeRow (footerRow, fields);
+                               OnRowCreated (new GridViewRowEventArgs (footerRow));
+                               if (dataBinding) {
+                                       footerRow.DataBind ();
+                                       OnRowDataBound (new GridViewRowEventArgs (footerRow));
+                               }
 
-                       GridViewRow footerRow = CreateRow (0, 0, DataControlRowType.Footer, DataControlRowState.Normal);
-                       table.Rows.Add (footerRow);
-                       InitializeRow (footerRow, fields);
-                       OnRowCreated (new GridViewRowEventArgs (footerRow));
-                       if (dataBinding) {
-                               footerRow.DataBind ();
-                               OnRowDataBound (new GridViewRowEventArgs (footerRow));
-                       }
-
-                       if (showPager && PagerSettings.Position == PagerPosition.Bottom || PagerSettings.Position == PagerPosition.TopAndBottom) {
-                               bottomPagerRow = CreatePagerRow (fields.Length, dataSource);
-                               table.Rows.Add (bottomPagerRow);
-                               OnRowCreated (new GridViewRowEventArgs (bottomPagerRow));
+                               if (showPager && PagerSettings.Position == PagerPosition.Bottom || PagerSettings.Position == PagerPosition.TopAndBottom) {
+                                       bottomPagerRow = CreatePagerRow (fields.Length, dataSource);
+                                       ContainedTable.Rows.Add (bottomPagerRow);
+                                       OnRowCreated (new GridViewRowEventArgs (bottomPagerRow));
+                               }
                        }
 
                        rows = new GridViewRowCollection (list);
 
-                       return dataSource.DataSourceCount;
+                       if (!dataBinding)
+                               return -1;
+
+                       if (AllowPaging)
+                               return dataSource.DataSourceCount;
+                       else
+                               return list.Count;
+               }
+
+               Table ContainedTable  {
+                       get {
+                               if (table == null) {
+                                       table = CreateChildTable ();
+                                       Controls.Add (table);
+                               }
+                               return table;
+                       }
                }
 
                protected override Style CreateControlStyle ()
@@ -1359,6 +1375,9 @@ namespace System.Web.UI.WebControls
                
                GridViewRow CreateEmptyrRow (int fieldCount)
                {
+                       if (emptyDataTemplate == null && String.IsNullOrEmpty (EmptyDataText))
+                               return null;
+
                        GridViewRow row = CreateRow (-1, -1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal);
                        TableCell cell = new TableCell ();
                        cell.ColumnSpan = fieldCount;