Author: igorz
Date: 2006-11-01 09:03:44 -0500 (Wed, 01 Nov 2006)
New Revision: 67218

Modified:
   trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
   trunk/mcs/class/System.Web/System.Web.UI.WebControls/GridView.cs
   trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/ChangeLog
   trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/GridViewTest.cs
Log:
2006-11-01 Igor Zelmanovich <[EMAIL PROTECTED]>

        * GridView.cs: fixed: UpdateRow, DeleteRow, RowCreated.



Modified: trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog      
2006-11-01 13:40:57 UTC (rev 67217)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog      
2006-11-01 14:03:44 UTC (rev 67218)
@@ -1,5 +1,9 @@
 2006-11-01 Igor Zelmanovich <[EMAIL PROTECTED]>
 
+       * GridView.cs: fixed: UpdateRow, DeleteRow, RowCreated.
+
+2006-11-01 Igor Zelmanovich <[EMAIL PROTECTED]>
+
        * FormView.cs: fixed: UpdateItem, DeleteItem.
 
 2006-10-31 Igor Zelmanovich <[EMAIL PROTECTED]>

Modified: trunk/mcs/class/System.Web/System.Web.UI.WebControls/GridView.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/GridView.cs    
2006-11-01 13:40:57 UTC (rev 67217)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/GridView.cs    
2006-11-01 14:03:44 UTC (rev 67218)
@@ -1117,7 +1117,6 @@
                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 @@
                                        dataSource.CurrentPageIndex = PageIndex;
                                        if (view.CanPage) {
                                                dataSource.AllowServerPaging = 
true;
-                                               if 
(view.CanRetrieveTotalRowCount)
+                                               if 
(SelectArguments.RetrieveTotalRowCount)
                                                        dataSource.VirtualCount 
= SelectArguments.TotalRowCount;
                                        }
                                }
@@ -1193,11 +1192,13 @@
                        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 @@
                                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 @@
                                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 @@
                                                param = row.RowIndex.ToString();
                                }
                                ProcessEvent (args.CommandName, param);
+                               return true;
                        }
                        return base.OnBubbleEvent (source, e);
                }
@@ -1519,13 +1527,15 @@
                                        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,13 +1652,16 @@
                [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;
                        currentEditNewValues = GetRowValues (row, false, false);
@@ -1657,8 +1670,10 @@
                        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 @@
                        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);

Modified: trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/ChangeLog 
2006-11-01 13:40:57 UTC (rev 67217)
+++ trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/ChangeLog 
2006-11-01 14:03:44 UTC (rev 67218)
@@ -1,5 +1,9 @@
 2006-11-01 Igor Zelmanovich <[EMAIL PROTECTED]>
 
+       * GridViewTest.cs: removed NotWorking attributes, fixed tests
+                       
+2006-11-01 Igor Zelmanovich <[EMAIL PROTECTED]>
+
        * FormViewRowTest.cs: removed NotWorking attributes
        * FormViewTest.cs: removed NotWorking attributes, fixed tests
                        

Modified: 
trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/GridViewTest.cs
===================================================================
--- trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/GridViewTest.cs   
2006-11-01 13:40:57 UTC (rev 67217)
+++ trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/GridViewTest.cs   
2006-11-01 14:03:44 UTC (rev 67218)
@@ -647,10 +647,17 @@
 
 
                [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 @@
                }
 
                [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 @@
                {
                        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 @@
                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 @@
                private int newPageIndex;
 
                [Test]
-               [Category ("NotWorking")]
                public void GridView_BubbleEvent ()
                {
                        PokerGridView gv = new PokerGridView ();
@@ -846,6 +879,9 @@
                        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 @@
                        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 @@
                        bubblepage = true;
                        pageIndexChanging = true;
                        newPageIndex = e.NewPageIndex;
+                       e.NewPageIndex = 0;
                }
 
                private void ResetEvents ()
@@ -1912,7 +1949,6 @@
 
                [Test]
                [Category ("NunitWeb")]
-               [Category ("NotWorking")]
                public void GridView_PostBackDelete ()
                {
                        WebTest t = new WebTest (PageInvoker.CreateOnLoad 
(GridView_postback));

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to