diff options
author | Igor Zelmanovich <igorz@mono-cvs.ximian.com> | 2006-11-01 17:03:44 +0300 |
---|---|---|
committer | Igor Zelmanovich <igorz@mono-cvs.ximian.com> | 2006-11-01 17:03:44 +0300 |
commit | b2cf26705dcf2e84f3a34d444d9f216909baf10e (patch) | |
tree | 34b48d431b1c846121de6abefddf496bfdf04f7f /mcs/class | |
parent | 3d8b7db49c4e9ef1d8d8cdd69c6b1fc2b6f08c19 (diff) |
2006-11-01 Igor Zelmanovich <igorz@mainsoft.com>
* GridView.cs: fixed: UpdateRow, DeleteRow, RowCreated.
svn path=/trunk/mcs/; revision=67218
Diffstat (limited to 'mcs/class')
4 files changed, 80 insertions, 21 deletions
diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog b/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog index 40c07730680..97e79efb34b 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog +++ b/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog @@ -1,5 +1,9 @@ 2006-11-01 Igor Zelmanovich <igorz@mainsoft.com> + * GridView.cs: fixed: UpdateRow, DeleteRow, RowCreated. + +2006-11-01 Igor Zelmanovich <igorz@mainsoft.com> + * FormView.cs: fixed: UpdateItem, DeleteItem. 2006-10-31 Igor Zelmanovich <igorz@mainsoft.com> diff --git a/mcs/class/System.Web/System.Web.UI.WebControls/GridView.cs b/mcs/class/System.Web/System.Web.UI.WebControls/GridView.cs index 88c312dd5d3..5eede0633fe 100644 --- a/mcs/class/System.Web/System.Web.UI.WebControls/GridView.cs +++ b/mcs/class/System.Web/System.Web.UI.WebControls/GridView.cs @@ -1117,7 +1117,6 @@ namespace System.Web.UI.WebControls protected virtual GridViewRow CreateRow (int rowIndex, int dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState) { GridViewRow row = new GridViewRow (rowIndex, dataSourceIndex, rowType, rowState); - OnRowCreated (new GridViewRowEventArgs (row)); return row; } @@ -1149,7 +1148,7 @@ namespace System.Web.UI.WebControls dataSource.CurrentPageIndex = PageIndex; if (view.CanPage) { dataSource.AllowServerPaging = true; - if (view.CanRetrieveTotalRowCount) + if (SelectArguments.RetrieveTotalRowCount) dataSource.VirtualCount = SelectArguments.TotalRowCount; } } @@ -1193,11 +1192,13 @@ namespace System.Web.UI.WebControls 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)); foreach (object obj in dataSource) { DataControlRowState rstate = GetRowState (list.Count); @@ -1206,6 +1207,7 @@ namespace System.Web.UI.WebControls list.Add (row); table.Rows.Add (row); InitializeRow (row, fields); + OnRowCreated (new GridViewRowEventArgs (row)); if (dataBinding) { row.DataBind (); OnRowDataBound (new GridViewRowEventArgs (row)); @@ -1221,17 +1223,22 @@ namespace System.Web.UI.WebControls if (list.Count >= PageSize) break; } - - if (list.Count == 0) - table.Rows.Add (CreateEmptyrRow (fields.Length)); + + if (list.Count == 0) { + GridViewRow emptyRow = CreateEmptyrRow (fields.Length); + table.Rows.Add (emptyRow); + OnRowCreated (new GridViewRowEventArgs (emptyRow)); + } GridViewRow footerRow = CreateRow (0, 0, DataControlRowType.Footer, DataControlRowState.Normal); table.Rows.Add (footerRow); InitializeRow (footerRow, fields); + OnRowCreated (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)); } rows = new GridViewRowCollection (list); @@ -1486,6 +1493,7 @@ namespace System.Web.UI.WebControls param = row.RowIndex.ToString(); } ProcessEvent (args.CommandName, param); + return true; } return base.OnBubbleEvent (source, e); } @@ -1519,13 +1527,15 @@ namespace System.Web.UI.WebControls newIndex = PageCount - 1; break; case DataControlCommands.NextPageCommandArgument: - if (PageIndex < PageCount - 1) newIndex = PageIndex + 1; + newIndex = PageIndex + 1; break; case DataControlCommands.PreviousPageCommandArgument: - if (PageIndex > 0) newIndex = PageIndex - 1; + newIndex = PageIndex - 1; break; default: - newIndex = int.Parse (param) - 1; + int paramIndex = 0; + int.TryParse (param, out paramIndex); + newIndex = paramIndex - 1; break; } ShowPage (newIndex); @@ -1642,12 +1652,15 @@ namespace System.Web.UI.WebControls [MonoTODO ("Support two-way binding expressions")] public virtual void UpdateRow (int rowIndex, bool causesValidation) { - if (causesValidation) + if (causesValidation && Page != null) Page.Validate (); if (rowIndex != EditIndex) throw new NotSupportedException (); - - currentEditOldValues = oldEditValues.Values; + + if (oldEditValues == null) + currentEditOldValues = new OrderedDictionary (); + else + currentEditOldValues = oldEditValues.Values; GridViewRow row = Rows [rowIndex]; currentEditRowKeys = DataKeys [rowIndex].Values; @@ -1657,8 +1670,10 @@ namespace System.Web.UI.WebControls OnRowUpdating (args); if (!args.Cancel) { DataSourceView view = GetData (); - if (view == null) throw new HttpException ("The DataSourceView associated to data bound control was null"); - view.Update (currentEditRowKeys, currentEditNewValues, currentEditOldValues, new DataSourceViewOperationCallback (UpdateCallback)); + if (view == null) + throw new HttpException ("The DataSourceView associated to data bound control was null"); + if(view.CanUpdate) + view.Update (currentEditRowKeys, currentEditNewValues, currentEditOldValues, new DataSourceViewOperationCallback (UpdateCallback)); } else EndRowEdit (); } @@ -1686,7 +1701,7 @@ namespace System.Web.UI.WebControls if (!args.Cancel) { RequireBinding (); DataSourceView view = GetData (); - if (view != null) + if (view != null && view.CanDelete) view.Delete (currentEditRowKeys, currentEditNewValues, new DataSourceViewOperationCallback (DeleteCallback)); else { GridViewDeletedEventArgs dargs = new GridViewDeletedEventArgs (0, null, currentEditRowKeys, currentEditNewValues); 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 1da9bd4677a..4a65e2630fa 100644 --- a/mcs/class/System.Web/Test/System.Web.UI.WebControls/ChangeLog +++ b/mcs/class/System.Web/Test/System.Web.UI.WebControls/ChangeLog @@ -1,5 +1,9 @@ 2006-11-01 Igor Zelmanovich <igorz@mainsoft.com> + * GridViewTest.cs: removed NotWorking attributes, fixed tests + +2006-11-01 Igor Zelmanovich <igorz@mainsoft.com> + * FormViewRowTest.cs: removed NotWorking attributes * FormViewTest.cs: removed NotWorking attributes, fixed tests diff --git a/mcs/class/System.Web/Test/System.Web.UI.WebControls/GridViewTest.cs b/mcs/class/System.Web/Test/System.Web.UI.WebControls/GridViewTest.cs index 5e506e1edd8..cc85e2163bd 100644 --- a/mcs/class/System.Web/Test/System.Web.UI.WebControls/GridViewTest.cs +++ b/mcs/class/System.Web/Test/System.Web.UI.WebControls/GridViewTest.cs @@ -647,10 +647,17 @@ namespace MonoTests.System.Web.UI.WebControls [Test] - [Category ("NotWorking")] public void GridView_DeleteItem() { PokerGridView g = new PokerGridView (); + ArrayList myds = new ArrayList (); + myds.Add ("Norway"); + myds.Add ("Sweden"); + myds.Add ("France"); + myds.Add ("Italy"); + + g.DataSource = myds; + g.DataBind (); Assert.AreEqual (false, deleteitemchecker, "DeleteItem#1"); g.RowDeleting += new GridViewDeleteEventHandler (RowDeletingHandler); g.DeleteRow (0); @@ -663,10 +670,14 @@ namespace MonoTests.System.Web.UI.WebControls } [Test] - [Category ("NotWorking")] public void GridView_RowCreated () { GridView g = new GridView (); + ButtonField field = new ButtonField (); + field.ButtonType = ButtonType.Link; + field.Text = "Click"; + field.CommandName = "CMD"; + g.Columns.Add (field); g.RowCreated += new GridViewRowEventHandler (RowCreatedHandler); Assert.AreEqual (false, rowcreatedchecker, "RowCreated#1"); @@ -686,6 +697,22 @@ namespace MonoTests.System.Web.UI.WebControls { if (e.Row.Cells.Count > 0) rowcreatedchecker = true; + + // Example from MSDN: GridView.RowCreated Event + + // The GridViewCommandEventArgs class does not contain a + // property that indicates which row's command button was + // clicked. To identify which row's button was clicked, use + // the button's CommandArgument property by setting it to the + // row's index. + if (e.Row.RowType == DataControlRowType.DataRow) { + // Retrieve the LinkButton control from the first column. + IButtonControl addButton = (IButtonControl) e.Row.Cells [0].Controls [0]; + + // Set the LinkButton's CommandArgument property with the + // row's index. + addButton.CommandArgument = e.Row.RowIndex.ToString (); + } } [Test] @@ -728,8 +755,15 @@ namespace MonoTests.System.Web.UI.WebControls public void GridView_CreateChildControls () { PokerGridView g = new PokerGridView (); + g.Page = new Page (); g.DataSource = myds; + g.DataBind (); Assert.AreEqual(6,g.DoCreateChildControls(myds,true),"CreateChildControls#1"); + + g.AllowPaging = true; + g.PageSize = 3; + g.DataBind (); + Assert.AreEqual (6, g.DoCreateChildControls (myds, true), "CreateChildControls#1"); } [Test] @@ -838,7 +872,6 @@ namespace MonoTests.System.Web.UI.WebControls private int newPageIndex; [Test] - [Category ("NotWorking")] public void GridView_BubbleEvent () { PokerGridView gv = new PokerGridView (); @@ -846,6 +879,9 @@ namespace MonoTests.System.Web.UI.WebControls LinkButton lb = new LinkButton (); gv.AllowPaging = true; page.Controls.Add (gv); + gv.DataSource = myds; + gv.DataBind (); + gv.EditIndex = 0; // gv.RowDeleting += new GridViewDeleteEventHandler (gv_RowDeleting); gv.RowUpdating += new GridViewUpdateEventHandler (gv_RowUpdating); @@ -855,17 +891,17 @@ namespace MonoTests.System.Web.UI.WebControls gv.SelectedIndexChanging+=new GridViewSelectEventHandler(gv_SelectedIndexChanging); gv.PageIndexChanging+=new GridViewPageEventHandler(gv_PageIndexChanging); // Delete - GridViewCommandEventArgs com1 = new GridViewCommandEventArgs (lb, new CommandEventArgs ("Delete", null)); + GridViewCommandEventArgs com1 = new GridViewCommandEventArgs (lb, new CommandEventArgs ("Delete", "0")); Assert.AreEqual (false, bubbledeleterow, "BeforeBubbleEventDeleteRow"); gv.DoOnBubbleEvent (gv, com1); Assert.AreEqual (true, bubbledeleterow, "AfterBubbleEventDeleteRow"); // Update - GridViewCommandEventArgs com2 = new GridViewCommandEventArgs (lb, new CommandEventArgs ("Update", null)); + GridViewCommandEventArgs com2 = new GridViewCommandEventArgs (lb, new CommandEventArgs ("Update", "0")); Assert.AreEqual (false, bubbleupdaterow, "BeforeBubbleEventUpdateRow"); gv.DoOnBubbleEvent (gv, com2); Assert.AreEqual (true, bubbleupdaterow, "AfterBubbleEventUpdateRow"); // Edit - GridViewCommandEventArgs com3 = new GridViewCommandEventArgs (lb, new CommandEventArgs ("Edit", null)); + GridViewCommandEventArgs com3 = new GridViewCommandEventArgs (lb, new CommandEventArgs ("Edit", "0")); Assert.AreEqual (false, bubbleeditingrow, "BeforeBubbleEventEditingRow"); gv.DoOnBubbleEvent (gv, com3); Assert.AreEqual (true, bubbleeditingrow, "AfterBubbleEventEditingRow"); @@ -953,6 +989,7 @@ namespace MonoTests.System.Web.UI.WebControls bubblepage = true; pageIndexChanging = true; newPageIndex = e.NewPageIndex; + e.NewPageIndex = 0; } private void ResetEvents () @@ -1912,7 +1949,6 @@ namespace MonoTests.System.Web.UI.WebControls [Test] [Category ("NunitWeb")] - [Category ("NotWorking")] public void GridView_PostBackDelete () { WebTest t = new WebTest (PageInvoker.CreateOnLoad (GridView_postback)); |