diff options
author | Konstantin Triger <kostat@mono-cvs.ximian.com> | 2006-04-20 13:15:05 +0400 |
---|---|---|
committer | Konstantin Triger <kostat@mono-cvs.ximian.com> | 2006-04-20 13:15:05 +0400 |
commit | 9c61d86aa0729cc35131e0bd00a1573207ec6c21 (patch) | |
tree | 1b2773fda08e3e1f87941fb3a3cbb8c424e248f2 /mcs | |
parent | bfd8d4d62e75ecb6285dcc18c2c5ee9c80599f65 (diff) |
ensure rebinding when FormView.PageIndex is called
svn path=/trunk/mcs/; revision=59688
Diffstat (limited to 'mcs')
5 files changed, 76 insertions, 36 deletions
diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/BaseDataBoundControl.cs b/mcs/class/System.Web/System.Web.UI.WebControls/BaseDataBoundControl.cs index 50c9f8faac9..71ae65da7c1 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/BaseDataBoundControl.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/BaseDataBoundControl.cs @@ -45,6 +45,7 @@ namespace System.Web.UI.WebControls { object dataSource; bool initialized; + bool preRendered; bool requiresDataBinding; protected BaseDataBoundControl () @@ -97,7 +98,11 @@ namespace System.Web.UI.WebControls { protected bool RequiresDataBinding { get { return requiresDataBinding; } - set { requiresDataBinding = value; } + set { + requiresDataBinding = value; + if (value && preRendered && IsBoundUsingDataSourceID && Page != null && !Page.IsCallback) + EnsureDataBound (); + } } protected void ConfirmInitState () @@ -141,6 +146,7 @@ namespace System.Web.UI.WebControls { protected internal override void OnPreRender (EventArgs e) { + preRendered = true; EnsureDataBound (); base.OnPreRender (e); } diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog b/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog index 8caf4639c84..9984fd1d328 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog +++ b/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog @@ -1,5 +1,13 @@ 2006-04-20 Konstantin Triger <kostat@mainsoft.com> + * BaseDataBoundControl.cs: RequiresDataBinding rebinds if the control prerendered. + * FormView.cs: + enable binding. + ensure rebinding when FormView.PageIndex is called. + and bind to the correct PageIndex. + +2006-04-20 Konstantin Triger <kostat@mainsoft.com> + * MenuItem.cs: when binding to IHierarchyData, check whether it implements INavigateUIData and retrieve NavigateUrl. * CompositeDataBoundControl.cs: ensures data is bound before creating child controls. diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/FormView.cs b/mcs/class/System.Web/System.Web.UI.WebControls/FormView.cs index ca5e4db4296..49585b9598e 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/FormView.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/FormView.cs @@ -806,55 +806,39 @@ namespace System.Web.UI.WebControls [MonoTODO] protected override void EnsureDataBound () { - throw new NotImplementedException (); + base.EnsureDataBound (); } [MonoTODO] protected override Style CreateControlStyle () { - throw new NotImplementedException (); + return base.CreateControlStyle (); } protected override int CreateChildControls (IEnumerable data, bool dataBinding) { - PagedDataSource dataSource; + PagedDataSource dataSource = new PagedDataSource (); + dataSource.DataSource = data; + dataSource.AllowPaging = AllowPaging; + dataSource.PageSize = 1; + dataSource.CurrentPageIndex = PageIndex; if (dataBinding) { DataSourceView view = GetData (); - dataSource = new PagedDataSource (); - dataSource.DataSource = data; - - if (AllowPaging) { - dataSource.AllowPaging = true; - dataSource.PageSize = 1; - dataSource.CurrentPageIndex = PageIndex; - if (view.CanPage) { - dataSource.AllowServerPaging = true; - if (view.CanRetrieveTotalRowCount) - dataSource.VirtualCount = SelectArguments.TotalRowCount; - else { - dataSource.DataSourceView = view; - dataSource.DataSourceSelectArguments = SelectArguments; - dataSource.SetItemCountFromPageIndex (PageIndex + PagerSettings.PageButtonCount); - } + if (view.CanPage) { + dataSource.AllowServerPaging = true; + if (view.CanRetrieveTotalRowCount) + dataSource.VirtualCount = SelectArguments.TotalRowCount; + else { + dataSource.DataSourceView = view; + dataSource.DataSourceSelectArguments = SelectArguments; + dataSource.SetItemCountFromPageIndex (PageIndex + PagerSettings.PageButtonCount); } } - - pageCount = dataSource.PageCount; - } - else - { - dataSource = new PagedDataSource (); - dataSource.DataSource = data; - if (AllowPaging) { - dataSource.AllowPaging = true; - dataSource.PageSize = 1; - dataSource.CurrentPageIndex = PageIndex; - } } + pageCount = dataSource.Count; bool showPager = AllowPaging && (PageCount > 1); - dataSourceCount = dataSource.Count; Controls.Clear (); table = CreateTable (); @@ -866,10 +850,16 @@ namespace System.Web.UI.WebControls // Gets the current data item IEnumerator e = dataSource.GetEnumerator (); - if (e.MoveNext ()) - dataItem = e.Current; + dataItem = null; + + if (AllowPaging) { + if (e.MoveNext ()) + dataItem = e.Current; + } else - dataItem = null; + for (int page = 0; e.MoveNext (); page++ ) + if (page == PageIndex) + dataItem = e.Current; // Main table creation diff --git a/mcs/class/System.Web/Test/System.Web.UI.WebControls/ChangeLog b/mcs/class/System.Web/Test/System.Web.UI.WebControls/ChangeLog index 9c9776377c0..8b3da624348 100644 --- a/mcs/class/System.Web/Test/System.Web.UI.WebControls/ChangeLog +++ b/mcs/class/System.Web/Test/System.Web.UI.WebControls/ChangeLog @@ -1,3 +1,7 @@ +2006-04-20 Konstantin Triger <kostat@mainsoft.com> + + * FormViewTest.cs: added test for PageIndex. + 2006-04-06 Konstantin Triger <kostat@mainsoft.com> * DataListTest.cs: added test for DataSourceID. diff --git a/mcs/class/System.Web/Test/System.Web.UI.WebControls/FormViewTest.cs b/mcs/class/System.Web/Test/System.Web.UI.WebControls/FormViewTest.cs index 95d670c6f44..ff6204b4ce8 100644 --- a/mcs/class/System.Web/Test/System.Web.UI.WebControls/FormViewTest.cs +++ b/mcs/class/System.Web/Test/System.Web.UI.WebControls/FormViewTest.cs @@ -32,6 +32,7 @@ using NUnit.Framework; using System; using System.IO; +using System.Collections; using System.Globalization; using System.Web; using System.Web.UI; @@ -53,6 +54,16 @@ namespace MonoTests.System.Web.UI.WebControls public void LoadState (object state) { LoadViewState (state); } + + public void DoConfirmInitState () + { + base.ConfirmInitState (); + } + + public void DoOnPreRender (EventArgs e) + { + base.OnPreRender (e); + } } [Test] @@ -108,6 +119,27 @@ namespace MonoTests.System.Web.UI.WebControls Assert.AreEqual (0, p.DataItemCount, "A38"); Assert.AreEqual (0, p.DataItemIndex, "A39"); } + + [Test] + public void PageIndex () + { + ObjectDataSource ds = new ObjectDataSource (); + ds.ID = "ObjectDataSource1"; + ds.TypeName = "System.Guid"; + ds.SelectMethod = "ToByteArray"; + Page p = new Page (); + Poker f = new Poker (); + f.Page = p; + ds.Page = p; + p.Controls.Add (f); + p.Controls.Add (ds); + f.DataSourceID = "ObjectDataSource1"; + f.DoConfirmInitState (); + f.DoOnPreRender (EventArgs.Empty); + object cur = f.DataItem; + f.PageIndex = 1; + Assert.IsTrue (cur != f.DataItem, "#01"); + } } } #endif |