Преглед изворни кода

2007-03-19 Igor Zelmanovich <[email protected]>

	* DataGrid.cs: fixed Save/Load view state, applying styles.	

svn path=/trunk/mcs/; revision=74601
Igor Zelmanovich пре 19 година
родитељ
комит
08e94fae98

+ 1 - 0
mcs/class/System.Web/Makefile

@@ -90,6 +90,7 @@ TEST_RESOURCE_FILES = \
 	Test/mainsoft/NunitWebResources/Web.sitemap \
 	Test/mainsoft/NunitWebResources/WizardTest.skin \
 	Test/mainsoft/NunitWebResources/FooterTemplateTest.aspx \
+	Test/mainsoft/NunitWebResources/DataGrid.aspx \
 	Test/mainsoft/NunitWebResources/DetailsViewTemplates.aspx \
 	Test/mainsoft/NunitWebResources/DetailsViewDataActions.aspx \
 	Test/mainsoft/NunitWebResources/DetailsViewProperties1.aspx \

+ 4 - 0
mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog

@@ -1,3 +1,7 @@
+2007-03-19 Igor Zelmanovich <[email protected]>
+
+	* DataGrid.cs: fixed Save/Load view state, applying styles.	
+
 2007-03-12 Igor Zelmanovich <[email protected]>
 
 	* Style.cs: optimization: used CssStyleCollection .ctor w/o parameters.	

+ 77 - 28
mcs/class/System.Web/System.Web.UI.WebControls/DataGrid.cs

@@ -353,6 +353,7 @@ namespace System.Web.UI.WebControls {
 		[WebCategory ("Style")]
 		public virtual DataGridItemCollection Items {
 			get {
+				EnsureChildControls ();
 				if (items == null) {
 					if (items_list == null)
 						items_list = new ArrayList ();
@@ -577,6 +578,11 @@ namespace System.Web.UI.WebControls {
 			b.HeaderText = prop.Name;
 			b.DataField = (tothis ? BoundColumn.thisExpr : prop.Name);
 			b.SortExpression = prop.Name;
+#if NET_2_0
+			if (string.Compare (DataKeyField, b.DataField, StringComparison.InvariantCultureIgnoreCase) == 0) {
+				b.ReadOnly = true;
+			}
+#endif
 			DataSourceColumns.Add (b);
 		}
 
@@ -598,7 +604,10 @@ namespace System.Web.UI.WebControls {
 				selected_style.TrackViewState ();
 			if (edit_item_style != null)
 				edit_item_style.TrackViewState ();
-
+#if NET_2_0
+			if (ControlStyleCreated)
+				ControlStyle.TrackViewState ();
+#endif
 			IStateManager manager = (IStateManager) columns;
 			if (manager != null)
 				manager.TrackViewState ();
@@ -606,7 +615,11 @@ namespace System.Web.UI.WebControls {
 
 		protected override object SaveViewState ()
 		{
+#if NET_2_0
+			object [] res = new object [11];
+#else
 			object [] res = new object [10];
+#endif
 
 			res [0] = base.SaveViewState ();
 			if (columns != null) {
@@ -627,12 +640,21 @@ namespace System.Web.UI.WebControls {
 				res [7] = selected_style.SaveViewState ();
 			if (edit_item_style != null)
 				res [8] = edit_item_style.SaveViewState ();
-
+#if NET_2_0
+			if (ControlStyleCreated)
+				res [9] = ControlStyle.SaveViewState ();
+			
+			if (data_source_columns != null) {
+				IStateManager m = (IStateManager) data_source_columns;
+				res [10] = m.SaveViewState ();
+			}
+#else
 			if (data_source_columns != null) {
 				IStateManager m = (IStateManager) data_source_columns;
 				res [9] = m.SaveViewState ();
 			}
-			
+#endif
+
 			return res;
 		}
 
@@ -663,6 +685,23 @@ namespace System.Web.UI.WebControls {
 			if (pieces [8] != null)
 				EditItemStyle.LoadViewState (pieces [8]);
 
+#if NET_2_0
+			if (pieces [9] != null)
+				ControlStyle.LoadViewState (pieces [8]);
+
+			if (pieces [10] != null) {
+				// IStateManager manager = (IStateManager) DataSourceColumns;
+				// manager.LoadViewState (pieces [10]);
+				object [] cols = (object []) pieces [10];
+				foreach (object o in cols) {
+					BoundColumn c = new BoundColumn ();
+					((IStateManager) c).TrackViewState ();
+					c.Set_Owner (this);
+					((IStateManager) c).LoadViewState (o);
+					DataSourceColumns.Add (c);
+				}
+			}
+#else
 			if (pieces [9] != null) {
 				// IStateManager manager = (IStateManager) DataSourceColumns;
 				// manager.LoadViewState (pieces [9]);
@@ -674,11 +713,16 @@ namespace System.Web.UI.WebControls {
 					DataSourceColumns.Add (c);
 				}
 			}
+#endif
 		}
 
 		protected override Style CreateControlStyle ()
 		{
+#if NET_2_0
+			TableStyle res = new TableStyle ();
+#else
 			TableStyle res = new TableStyle (ViewState);
+#endif
 			res.GridLines = GridLines.Both;
 			res.CellSpacing = 0;
 			return res;
@@ -782,7 +826,11 @@ namespace System.Web.UI.WebControls {
 				l.Text = PagerStyle.PrevPageText;
 				prev = l;
 			} else {
+#if NET_2_0
+				LinkButton l = new DataControlLinkButton ();
+#else
 				LinkButton l = new LinkButton ();
+#endif
 				l.Text = PagerStyle.PrevPageText;
 				l.CommandName = PageCommandName;
 				l.CommandArgument = PrevPageCommandArgument;
@@ -791,7 +839,11 @@ namespace System.Web.UI.WebControls {
 			}
 
 			if (paged.Count > 0 && !paged.IsLastPage) {
+#if NET_2_0
+				LinkButton l = new DataControlLinkButton ();
+#else
 				LinkButton l = new LinkButton ();
+#endif
 				l.Text = PagerStyle.NextPageText;
 				l.CommandName = PageCommandName;
 				l.CommandArgument = NextPageCommandArgument;
@@ -889,7 +941,14 @@ namespace System.Web.UI.WebControls {
 			IEnumerable data_source;
 			ArrayList keys = null;
 			if (useDataSource) {
+#if NET_2_0
+				if (IsBoundUsingDataSourceID)
+					data_source = GetData ();
+				else
+#endif
 				data_source = DataSourceResolver.ResolveDataSource (DataSource, DataMember);
+				if (data_source == null)
+					return;
 				keys = DataKeysArray;
 				keys.Clear ();
 			} else {
@@ -921,12 +980,7 @@ namespace System.Web.UI.WebControls {
 				render_columns [c] = col;
 			}
 
-			if (useDataSource) {
-				if (DataSource != null)
-					Controls.Add (RenderTable);
-			} else {
-				Controls.Add (RenderTable);
-			}
+			Controls.Add (RenderTable);
 
 			if (pds.IsPagingEnabled)
 				CreateItem (-1, -1, ListItemType.Pager, false, null, pds);
@@ -1033,30 +1087,18 @@ namespace System.Web.UI.WebControls {
 			rt.Enabled = Enabled;
 
 			bool top_pager = true;
-			Style alt = null;
 			foreach (DataGridItem item in rt.Rows) {
 				
 				switch (item.ItemType) {
 				case ListItemType.Item:
-					item.MergeStyle (item_style);
-					ApplyColumnStyle (item.Cells, ListItemType.Item);
+					ApplyItemStyle (item);
 					break;
 				case ListItemType.AlternatingItem:
-					if (alt == null) {
-						if (alt_item_style != null) {
-							alt = new TableItemStyle ();
-							alt.CopyFrom (item_style);
-							alt.CopyFrom (alt_item_style);
-						} else {
-							alt = item_style;
-						}
-					}
-
-					item.MergeStyle (alt);
-					ApplyColumnStyle (item.Cells, ListItemType.AlternatingItem);
+					ApplyItemStyle (item);
 					break;
 				case ListItemType.EditItem:
 					item.MergeStyle (edit_item_style);
+					ApplyItemStyle (item);
 					ApplyColumnStyle (item.Cells, ListItemType.EditItem);
 					break;
 				case ListItemType.Footer:
@@ -1078,10 +1120,8 @@ namespace System.Web.UI.WebControls {
 					ApplyColumnStyle (item.Cells, ListItemType.Header);
 					break;
 				case ListItemType.SelectedItem:
-					if (selected_style != null)
-						item.MergeStyle (selected_style);
-					else
-						item.MergeStyle (item_style);
+					item.MergeStyle (selected_style);
+					ApplyItemStyle (item);
 					ApplyColumnStyle (item.Cells, ListItemType.SelectedItem);
 					break;
 				case ListItemType.Separator:
@@ -1106,6 +1146,15 @@ namespace System.Web.UI.WebControls {
 			}
 		}
 
+		void ApplyItemStyle (DataGridItem item)
+		{
+			if (item.ItemIndex % 2 != 0)
+				item.MergeStyle (alt_item_style);
+
+			item.MergeStyle (item_style);
+			ApplyColumnStyle (item.Cells, ListItemType.Item);
+		}
+
 		protected override bool OnBubbleEvent (object source, EventArgs e)
 		{
 			DataGridCommandEventArgs de = e as DataGridCommandEventArgs;

+ 4 - 0
mcs/class/System.Web/Test/System.Web.UI.WebControls/ChangeLog

@@ -1,3 +1,7 @@
+2007-03-19 Igor Zelmanovich <[email protected]>
+
+	* DataGridTest.cs: Added new tests.
+
 2007-03-09  Marek Habersack  <[email protected]>
 
 	* LoginTest.cs: Added a test for case-insensitive command name in

+ 739 - 2
mcs/class/System.Web/Test/System.Web.UI.WebControls/DataGridTest.cs

@@ -41,6 +41,11 @@ using System.Collections;
 using System.Data;
 using System.ComponentModel;
 using System.Diagnostics;
+#if NET_2_0
+using System.Collections.Generic;
+using MonoTests.SystemWeb.Framework;
+using MonoTests.stand_alone.WebHarness;
+#endif
 
 namespace MonoTests.System.Web.UI.WebControls {
 
@@ -178,6 +183,24 @@ namespace MonoTests.System.Web.UI.WebControls {
 	[TestFixture]
 	public class DataGridTest {
 
+#if NET_2_0
+		[TestFixtureSetUp()]
+		public void FixtureSetup () 
+		{
+#if VISUAL_STUDIO
+			WebTest.CopyResource (GetType (), "MonoTests.System.Web.UI.WebControls.Resources.DataGrid.aspx", "DataGrid.aspx");
+#else
+			WebTest.CopyResource (GetType (), "DataGrid.aspx", "DataGrid.aspx");
+#endif
+		}
+
+		[TestFixtureTearDown()]
+		public void FixtureTearDown () 
+		{
+			WebTest.Unload ();
+		}
+#endif
+
 		[Test]
 		public void Defaults ()
 		{
@@ -440,7 +463,6 @@ namespace MonoTests.System.Web.UI.WebControls {
 		}
 
 		[Test]
-        [NUnit.Framework.Category("NotWorking")]
 		public void Styles ()
 		{
 			DataGridPoker p = new DataGridPoker ();
@@ -935,7 +957,6 @@ namespace MonoTests.System.Web.UI.WebControls {
 		}
 
 		[Test]
-        [NUnit.Framework.Category("NotWorking")]
 		public void SaveViewState ()
 		{
 			DataGridPoker p = new DataGridPoker ();
@@ -1007,6 +1028,15 @@ namespace MonoTests.System.Web.UI.WebControls {
 			vs = (object []) p.SaveState ();
 #if NET_2_0
 			Assert.IsNull (vs [9], "A12");
+			p.BackImageUrl = "foobar url";
+			vs = (object []) p.SaveState ();
+			Assert.IsNotNull (vs [9], "A12");
+
+			Assert.IsNotNull (vs [10], "A12");
+			Assert.AreEqual (vs [10].GetType (), typeof (object []), "A12");
+
+			object [] cols = (object []) vs [10];
+			Assert.AreEqual (cols.Length, 3, "A13");
 #else
 			Assert.IsNotNull (vs [9], "A12");
 			Assert.AreEqual (vs [9].GetType (), typeof (object []), "A12");
@@ -1326,6 +1356,713 @@ namespace MonoTests.System.Web.UI.WebControls {
 			Assert.AreEqual (0, p.DataKeys.Count, "A3");
 		}
 
+#if NET_2_0
+		public class data
+		{
+			private static ArrayList _data = new ArrayList ();
+
+			static data () {
+				_data.Add (new DataItem (1, "heh1"));
+				_data.Add (new DataItem (2, "heh2"));
+				_data.Add (new DataItem (3, "heh3"));
+				_data.Add (new DataItem (4, "heh4"));
+				_data.Add (new DataItem (5, "heh5"));
+				_data.Add (new DataItem (6, "heh6"));
+				_data.Add (new DataItem (7, "heh7"));
+				_data.Add (new DataItem (8, "heh8"));
+				_data.Add (new DataItem (9, "heh9"));
+				_data.Add (new DataItem (10, "heh10"));
+			}
+
+			public data () {
+			}
+
+			public ArrayList GetAllItems () {
+				return _data;
+			}
+
+			public ArrayList GetPagedItems (int startIndex, int maxRows) 
+			{
+				ArrayList list = new ArrayList ();
+				if (startIndex < _data.Count - 1) {
+					int countToReturn = Math.Min (maxRows, _data.Count - startIndex);
+					for (int i = startIndex; i < startIndex + countToReturn; i++) {
+						list.Add (_data [i]);
+					}
+				}
+
+				return list;
+			}
+
+			public int GetCount () 
+			{
+				return _data.Count;
+			}
+
+			public void UpdateItem (int id, string name) {
+				foreach (DataItem i in _data) {
+					if (i.ID == id) {
+						i.Name = name;
+						return;
+					}
+				}
+			}
+		}
+
+		public class DataItem
+		{
+			int _id = 0;
+			string _name = "";
+
+			public DataItem (int id, string name) {
+				_id = id;
+				_name = name;
+			}
+
+			public int ID {
+				get { return _id; }
+			}
+
+			public string Name {
+				get { return _name; }
+				set { _name = value; }
+			}
+		}
+
+		public class DataSourceObject
+		{
+			public static List<string> GetList (string sortExpression, int startRowIndex, int maximumRows) {
+				return GetList ();
+			}
+
+			public static List<string> GetList (int startRowIndex, int maximumRows) {
+				return GetList ();
+			}
+
+			public static List<string> GetList (string sortExpression) {
+				return GetList ();
+			}
+
+			public static List<string> GetList () {
+				List<string> list = new List<string> ();
+				list.Add ("Norway");
+				list.Add ("Sweden");
+				list.Add ("France");
+				list.Add ("Italy");
+				list.Add ("Israel");
+				list.Add ("Russia");
+				return list;
+			}
+
+			public static int GetCount () {
+				return GetList ().Count;
+			}
+		}
+
+		[Test]
+		[ExpectedException(typeof(InvalidOperationException))]
+		public void DataSourceAndDataSourceID () 
+		{
+			Page page = new Page ();
+			DataGridPoker dg = new DataGridPoker ();
+			
+			page.Controls.Add (dg);
+
+			DataTable dt = new DataTable ();
+			dt.Columns.Add (new DataColumn ("something", typeof (Int32)));
+			DataRow dr = dt.NewRow ();
+			dt.Rows.Add (new object [] { 1 });
+			DataView dv = new DataView (dt);
+
+			dg.DataSource = dv;
+
+			ObjectDataSource ds = new ObjectDataSource ();
+			ds.TypeName = typeof (DataSourceObject).AssemblyQualifiedName;
+			ds.SelectMethod = "GetList";
+			ds.SortParameterName = "sortExpression";
+			ds.ID = "Data";
+			page.Controls.Add (ds);
+
+			dg.DataSourceID = "Data";
+
+			dg.DataBind ();
+		}
+
+		[Test]
+		public void DataBindingDataSourceID () 
+		{
+			Page page = new Page ();
+			DataGridPoker dg = new DataGridPoker ();
+			page.Controls.Add (dg);
+
+			ObjectDataSource ds = new ObjectDataSource ();
+			ds.TypeName = typeof (DataSourceObject).AssemblyQualifiedName;
+			ds.SelectMethod = "GetList";
+			ds.SortParameterName = "sortExpression";
+			ds.ID = "Data";
+			page.Controls.Add (ds);
+
+			dg.DataSourceID = "Data";
+			dg.DataBind ();
+
+			Assert.AreEqual (6, dg.Items.Count, "DataBindingDataSourceID");
+		}
+
+		[Test]
+		[NUnit.Framework.Category ("NunitWeb")]
+		public void DataBindingDataSourceIDAutomatic () 
+		{
+			WebTest t = new WebTest ();
+			PageDelegates pd = new PageDelegates();
+			pd.Load = DataSourceIDAutomatic_Load;
+			pd.PreRender = DataSourceIDAutomatic_PreRender;
+			t.Invoker = new PageInvoker (pd);
+
+			t.Run ();
+		}
+
+		public static void DataSourceIDAutomatic_Load (Page page) 
+		{
+			DataGridPoker dg = new DataGridPoker ();
+			dg.ID = "DataGrid";
+			page.Controls.Add (dg);
+
+			ObjectDataSource ds = new ObjectDataSource ();
+			ds.TypeName = typeof (DataSourceObject).AssemblyQualifiedName;
+			ds.SelectMethod = "GetList";
+			ds.SortParameterName = "sortExpression";
+			ds.ID = "Data";
+			page.Controls.Add (ds);
+
+			dg.DataSourceID = "Data";
+		}
+
+		public static void DataSourceIDAutomatic_PreRender (Page page) 
+		{
+			DataGrid dg = (DataGrid)page.FindControl ("DataGrid");
+
+			Assert.AreEqual (6, dg.Items.Count, "DataBindingDataSourceID");
+		}
+
+		[Test]
+		public void DataSourceIDBindingNoColumns () 
+		{
+			Page page = new Page ();
+			DataGridPoker dg = new DataGridPoker ();
+			dg.ID = "DataGrid";
+			dg.AutoGenerateColumns = false;
+
+			page.Controls.Add (dg);
+
+			ObjectDataSource ds = new ObjectDataSource ();
+			ds.TypeName = typeof (DataSourceObject).AssemblyQualifiedName;
+			ds.SelectMethod = "GetList";
+			ds.SortParameterName = "sortExpression";
+			ds.ID = "Data";
+			page.Controls.Add (ds);
+
+			dg.DataSourceID = "Data";
+			dg.DataBind ();
+
+			Assert.AreEqual (0, dg.Columns.Count, "Columns Count");
+			Assert.AreEqual (0, dg.Items.Count, "Items Count");
+		}
+
+		[Test]
+		public void DataSourceIDBindingManualColumns () 
+		{
+			Page page = new Page ();
+			DataGridPoker dg = new DataGridPoker ();
+			dg.ID = "DataGrid";
+			dg.AutoGenerateColumns = false;
+			BoundColumn col = new BoundColumn();
+			col.DataField = "something";
+			dg.Columns.Add (col);
+
+			page.Controls.Add (dg);
+
+			DataTable dt = new DataTable ();
+			dt.Columns.Add (new DataColumn ("something", typeof (Int32)));
+			DataRow dr = dt.NewRow ();
+			dt.Rows.Add (new object [] { 1 });
+			dt.Rows.Add (new object [] { 2 });
+			dt.Rows.Add (new object [] { 3 });
+			dt.Rows.Add (new object [] { 4 });
+			dt.Rows.Add (new object [] { 5 });
+			dt.Rows.Add (new object [] { 6 });
+
+			DataView dv = new DataView (dt);
+
+			dg.DataSource = dv;
+			dg.DataBind ();
+
+			Assert.AreEqual (1, dg.Columns.Count, "Columns Count");
+			Assert.AreEqual (6, dg.Items.Count, "Items Count");
+			Assert.AreEqual ("1", dg.Items[0].Cells[0].Text, "Cell content");
+		}
+
+		[Test]
+		[NUnit.Framework.Category ("NunitWeb")]
+		public void Paging ()
+		{
+			WebTest t = new WebTest ("DataGrid.aspx");
+			t.Invoker = PageInvoker.CreateOnInit (DataGrid_OnInit);
+			string html = t.Run ();
+			string gridHtml = HtmlDiff.GetControlFromPageHtml (html);
+			string expectedFirstPage = @"<table cellspacing=""0"" cellpadding=""4"" border=""0"" id=""DataGrid1"" style=""color:#333333;border-collapse:collapse;"">
+	<tr style=""color:White;background-color:#990000;font-weight:bold;"">
+		<td>ID</td><td>Name</td><td>&nbsp;</td><td>&nbsp;</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl02$ctl00','')"" style=""color:White;"">ID</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl02$ctl01','')"" style=""color:White;"">Name</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl02$ctl02','')"" style=""color:White;"">Comment</a></td>
+	</tr><tr style=""color:#333333;background-color:#FFFBD6;"">
+		<td>1</td><td>heh1</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl03$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl03$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>1</td><td>heh1</td><td>Comment 1</td>
+	</tr><tr style=""color:#333333;background-color:White;"">
+		<td>2</td><td>heh2</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl04$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl04$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>2</td><td>heh2</td><td>Comment 2</td>
+	</tr><tr style=""color:#333333;background-color:#FFFBD6;"">
+		<td>3</td><td>heh3</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl05$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl05$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>3</td><td>heh3</td><td>Comment 3</td>
+	</tr><tr style=""color:#333333;background-color:White;"">
+		<td>4</td><td>heh4</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl06$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl06$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>4</td><td>heh4</td><td>Comment 4</td>
+	</tr><tr style=""color:#333333;background-color:#FFFBD6;"">
+		<td>5</td><td>heh5</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl07$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl07$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>5</td><td>heh5</td><td>Comment 5</td>
+	</tr><tr style=""color:White;background-color:#990000;font-weight:bold;"">
+		<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
+	</tr><tr align=""center"" style=""color:#333333;background-color:#FFCC66;"">
+		<td colspan=""4""><span>Previous</span>&nbsp;<a href=""javascript:__doPostBack('DataGrid1$ctl09$ctl01','')"" style=""color:#333333;"">Next</a></td>
+	</tr>
+</table>";
+
+			HtmlDiff.AssertAreEqual (expectedFirstPage, gridHtml, "DataGrid initial Render");
+
+			FormRequest fr = new FormRequest (t.Response, "form1");
+			fr.Controls.Add ("__EVENTTARGET");
+			fr.Controls.Add ("__EVENTARGUMENT");
+#if DOT_NET
+			fr.Controls ["__EVENTTARGET"].Value = "DataGrid1$ctl09$ctl01"; 
+#else
+			fr.Controls ["__EVENTTARGET"].Value = "DataGrid1$ctl08$ctl01c";
+#endif
+			fr.Controls ["__EVENTARGUMENT"].Value = "";
+			t.Request = fr;
+
+			html = t.Run ();
+			gridHtml = HtmlDiff.GetControlFromPageHtml (html);
+			string expectedSecondPage = @"<table cellspacing=""0"" cellpadding=""4"" border=""0"" id=""DataGrid1"" style=""color:#333333;border-collapse:collapse;"">
+	<tr style=""color:White;background-color:#990000;font-weight:bold;"">
+		<td>ID</td><td>Name</td><td>&nbsp;</td><td>&nbsp;</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl02$ctl00','')"" style=""color:White;"">ID</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl02$ctl01','')"" style=""color:White;"">Name</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl02$ctl02','')"" style=""color:White;"">Comment</a></td>
+	</tr><tr style=""color:#333333;background-color:#FFFBD6;"">
+		<td>6</td><td>heh6</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl03$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl03$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>6</td><td>heh6</td><td>Comment 6</td>
+	</tr><tr style=""color:#333333;background-color:White;"">
+		<td>7</td><td>heh7</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl04$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl04$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>7</td><td>heh7</td><td>Comment 7</td>
+	</tr><tr style=""color:#333333;background-color:#FFFBD6;"">
+		<td>8</td><td>heh8</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl05$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl05$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>8</td><td>heh8</td><td>Comment 8</td>
+	</tr><tr style=""color:#333333;background-color:White;"">
+		<td>9</td><td>heh9</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl06$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl06$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>9</td><td>heh9</td><td>Comment 9</td>
+	</tr><tr style=""color:#333333;background-color:#FFFBD6;"">
+		<td>10</td><td>heh10</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl07$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl07$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>10</td><td>heh10</td><td>Comment 10</td>
+	</tr><tr style=""color:White;background-color:#990000;font-weight:bold;"">
+		<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
+	</tr><tr align=""center"" style=""color:#333333;background-color:#FFCC66;"">
+		<td colspan=""4""><a href=""javascript:__doPostBack('DataGrid1$ctl09$ctl00','')"" style=""color:#333333;"">Previous</a>&nbsp;<span>Next</span></td>
+	</tr>
+</table>";
+			HtmlDiff.AssertAreEqual (expectedSecondPage, gridHtml, "DataGrid Paging Next");
+
+			fr = new FormRequest (t.Response, "form1");
+			fr.Controls.Add ("__EVENTTARGET");
+			fr.Controls.Add ("__EVENTARGUMENT");
+#if DOT_NET
+			fr.Controls ["__EVENTTARGET"].Value = "DataGrid1$ctl09$ctl00"; 
+#else
+			fr.Controls ["__EVENTTARGET"].Value = "DataGrid1$ctl08$ctl00c";
+#endif
+			fr.Controls ["__EVENTARGUMENT"].Value = "";
+			t.Request = fr;
+
+			html = t.Run ();
+			gridHtml = HtmlDiff.GetControlFromPageHtml (html);
+
+			HtmlDiff.AssertAreEqual (expectedFirstPage, gridHtml, "DataGrid Paging Previous");
+		}
+
+		[Test]
+		[NUnit.Framework.Category ("NunitWeb")]
+		public void EditUpdateDelete ()
+		{
+			WebTest t = new WebTest ("DataGrid.aspx");
+			t.Invoker = PageInvoker.CreateOnInit (DataGrid_OnInit);
+			string html = t.Run ();
+			string gridHtml = HtmlDiff.GetControlFromPageHtml (html);
+			string expectedFirstPage = @"<table cellspacing=""0"" cellpadding=""4"" border=""0"" id=""DataGrid1"" style=""color:#333333;border-collapse:collapse;"">
+	<tr style=""color:White;background-color:#990000;font-weight:bold;"">
+		<td>ID</td><td>Name</td><td>&nbsp;</td><td>&nbsp;</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl02$ctl00','')"" style=""color:White;"">ID</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl02$ctl01','')"" style=""color:White;"">Name</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl02$ctl02','')"" style=""color:White;"">Comment</a></td>
+	</tr><tr style=""color:#333333;background-color:#FFFBD6;"">
+		<td>1</td><td>heh1</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl03$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl03$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>1</td><td>heh1</td><td>Comment 1</td>
+	</tr><tr style=""color:#333333;background-color:White;"">
+		<td>2</td><td>heh2</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl04$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl04$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>2</td><td>heh2</td><td>Comment 2</td>
+	</tr><tr style=""color:#333333;background-color:#FFFBD6;"">
+		<td>3</td><td>heh3</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl05$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl05$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>3</td><td>heh3</td><td>Comment 3</td>
+	</tr><tr style=""color:#333333;background-color:White;"">
+		<td>4</td><td>heh4</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl06$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl06$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>4</td><td>heh4</td><td>Comment 4</td>
+	</tr><tr style=""color:#333333;background-color:#FFFBD6;"">
+		<td>5</td><td>heh5</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl07$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl07$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>5</td><td>heh5</td><td>Comment 5</td>
+	</tr><tr style=""color:White;background-color:#990000;font-weight:bold;"">
+		<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
+	</tr><tr align=""center"" style=""color:#333333;background-color:#FFCC66;"">
+		<td colspan=""4""><span>Previous</span>&nbsp;<a href=""javascript:__doPostBack('DataGrid1$ctl09$ctl01','')"" style=""color:#333333;"">Next</a></td>
+	</tr>
+</table>";
+
+			HtmlDiff.AssertAreEqual (expectedFirstPage, gridHtml, "DataGrid initial Render");
+
+			FormRequest fr = new FormRequest (t.Response, "form1");
+			fr.Controls.Add ("__EVENTTARGET");
+			fr.Controls.Add ("__EVENTARGUMENT");
+#if DOT_NET
+			fr.Controls ["__EVENTTARGET"].Value = "DataGrid1$ctl03$ctl00";
+#else
+			fr.Controls ["__EVENTTARGET"].Value = "DataGrid1$ctl02$ctl00c";
+#endif
+			fr.Controls ["__EVENTARGUMENT"].Value = "";
+			t.Request = fr;
+
+			html = t.Run ();
+			gridHtml = HtmlDiff.GetControlFromPageHtml (html);
+			string expectedSecondPage = @"<table cellspacing=""0"" cellpadding=""4"" border=""0"" id=""DataGrid1"" style=""color:#333333;border-collapse:collapse;"">
+	<tr style=""color:White;background-color:#990000;font-weight:bold;"">
+		<td>ID</td><td>Name</td><td>&nbsp;</td><td>&nbsp;</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl02$ctl00','')"" style=""color:White;"">ID</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl02$ctl01','')"" style=""color:White;"">Name</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl02$ctl02','')"" style=""color:White;"">Comment</a></td>
+	</tr><tr style=""color:#333333;background-color:Green;font-weight:normal;font-style:normal;text-decoration:none;"">
+		<td>1</td><td><input name=""DataGrid1$ctl03$ctl00"" type=""text"" value=""heh1"" /></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl03$ctl01','')"" style=""color:#333333;"">Update</a>&nbsp;<a href=""javascript:__doPostBack('DataGrid1$ctl03$ctl02','')"" style=""color:#333333;"">Cancel</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl03$ctl03','')"" style=""color:#333333;"">Delete</a></td><td>1</td><td><input name=""DataGrid1$ctl03$ctl04"" type=""text"" value=""heh1"" /></td><td><input name=""DataGrid1$ctl03$ctl05"" type=""text"" value=""Comment 1"" /></td>
+	</tr><tr style=""color:#333333;background-color:White;"">
+		<td>2</td><td>heh2</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl04$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl04$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>2</td><td>heh2</td><td>Comment 2</td>
+	</tr><tr style=""color:#333333;background-color:#FFFBD6;"">
+		<td>3</td><td>heh3</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl05$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl05$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>3</td><td>heh3</td><td>Comment 3</td>
+	</tr><tr style=""color:#333333;background-color:White;"">
+		<td>4</td><td>heh4</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl06$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl06$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>4</td><td>heh4</td><td>Comment 4</td>
+	</tr><tr style=""color:#333333;background-color:#FFFBD6;"">
+		<td>5</td><td>heh5</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl07$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl07$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>5</td><td>heh5</td><td>Comment 5</td>
+	</tr><tr style=""color:White;background-color:#990000;font-weight:bold;"">
+		<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
+	</tr><tr align=""center"" style=""color:#333333;background-color:#FFCC66;"">
+		<td colspan=""4""><span>Previous</span>&nbsp;<a href=""javascript:__doPostBack('DataGrid1$ctl09$ctl01','')"" style=""color:#333333;"">Next</a></td>
+	</tr>
+</table>";
+			HtmlDiff.AssertAreEqual (expectedSecondPage, gridHtml, "DataGrid Edit");
+
+			fr = new FormRequest (t.Response, "form1");
+			fr.Controls.Add ("__EVENTTARGET");
+			fr.Controls.Add ("__EVENTARGUMENT");
+#if DOT_NET
+			fr.Controls ["__EVENTTARGET"].Value = "DataGrid1$ctl03$ctl01";
+#else
+			fr.Controls ["__EVENTTARGET"].Value = "DataGrid1$ctl02$ctl01c";
+#endif
+			fr.Controls ["__EVENTARGUMENT"].Value = "";
+#if DOT_NET
+			fr.Controls.Add ("DataGrid1$ctl03$ctl00");
+			fr.Controls ["DataGrid1$ctl03$ctl00"].Value = "New Value";
+#else
+			fr.Controls.Add ("DataGrid1$ctl02$ctl00c");
+			fr.Controls ["DataGrid1$ctl02$ctl00c"].Value = "New Value";
+#endif
+			t.Request = fr;
+
+			html = t.Run ();
+			gridHtml = HtmlDiff.GetControlFromPageHtml (html);
+			string expectedThirdPage = @"
+        <table cellspacing=""0"" cellpadding=""4"" border=""0"" id=""DataGrid1"" style=""color:#333333;border-collapse:collapse;"">
+	<tr style=""color:White;background-color:#990000;font-weight:bold;"">
+		<td>ID</td><td>Name</td><td>&nbsp;</td><td>&nbsp;</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl02$ctl00','')"" style=""color:White;"">ID</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl02$ctl01','')"" style=""color:White;"">Name</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl02$ctl02','')"" style=""color:White;"">Comment</a></td>
+	</tr><tr style=""color:#333333;background-color:#FFFBD6;"">
+		<td>1</td><td>New Value</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl03$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl03$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>1</td><td>New Value</td><td>Comment 1</td>
+	</tr><tr style=""color:#333333;background-color:White;"">
+		<td>2</td><td>heh2</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl04$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl04$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>2</td><td>heh2</td><td>Comment 2</td>
+	</tr><tr style=""color:#333333;background-color:#FFFBD6;"">
+		<td>3</td><td>heh3</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl05$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl05$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>3</td><td>heh3</td><td>Comment 3</td>
+	</tr><tr style=""color:#333333;background-color:White;"">
+		<td>4</td><td>heh4</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl06$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl06$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>4</td><td>heh4</td><td>Comment 4</td>
+	</tr><tr style=""color:#333333;background-color:#FFFBD6;"">
+		<td>5</td><td>heh5</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl07$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl07$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>5</td><td>heh5</td><td>Comment 5</td>
+	</tr><tr style=""color:White;background-color:#990000;font-weight:bold;"">
+		<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
+	</tr><tr align=""center"" style=""color:#333333;background-color:#FFCC66;"">
+		<td colspan=""4""><span>Previous</span>&nbsp;<a href=""javascript:__doPostBack('DataGrid1$ctl09$ctl01','')"" style=""color:#333333;"">Next</a></td>
+	</tr>
+</table>";
+
+			HtmlDiff.AssertAreEqual (expectedThirdPage, gridHtml, "DataGrid Update");
+
+			fr = new FormRequest (t.Response, "form1");
+			fr.Controls.Add ("__EVENTTARGET");
+			fr.Controls.Add ("__EVENTARGUMENT");
+#if DOT_NET
+			fr.Controls ["__EVENTTARGET"].Value = "DataGrid1$ctl04$ctl01";
+#else
+			fr.Controls ["__EVENTTARGET"].Value = "DataGrid1$ctl03$ctl01c";
+#endif
+			fr.Controls ["__EVENTARGUMENT"].Value = "";
+			t.Request = fr;
+
+			html = t.Run ();
+			gridHtml = HtmlDiff.GetControlFromPageHtml (html);
+			string expectedFourthPage = @"
+        <table cellspacing=""0"" cellpadding=""4"" border=""0"" id=""DataGrid1"" style=""color:#333333;border-collapse:collapse;"">
+	<tr style=""color:White;background-color:#990000;font-weight:bold;"">
+		<td>ID</td><td>Name</td><td>&nbsp;</td><td>&nbsp;</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl02$ctl00','')"" style=""color:White;"">ID</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl02$ctl01','')"" style=""color:White;"">Name</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl02$ctl02','')"" style=""color:White;"">Comment</a></td>
+	</tr><tr style=""color:#333333;background-color:#FFFBD6;"">
+		<td>1</td><td>New Value</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl03$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl03$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>1</td><td>New Value</td><td>Comment 1</td>
+	</tr><tr style=""color:#333333;background-color:White;"">
+		<td>3</td><td>heh3</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl04$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl04$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>3</td><td>heh3</td><td>Comment 3</td>
+	</tr><tr style=""color:#333333;background-color:#FFFBD6;"">
+		<td>4</td><td>heh4</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl05$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl05$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>4</td><td>heh4</td><td>Comment 4</td>
+	</tr><tr style=""color:#333333;background-color:White;"">
+		<td>5</td><td>heh5</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl06$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl06$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>5</td><td>heh5</td><td>Comment 5</td>
+	</tr><tr style=""color:#333333;background-color:#FFFBD6;"">
+		<td>6</td><td>heh6</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl07$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl07$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>6</td><td>heh6</td><td>Comment 6</td>
+	</tr><tr style=""color:White;background-color:#990000;font-weight:bold;"">
+		<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
+	</tr><tr align=""center"" style=""color:#333333;background-color:#FFCC66;"">
+		<td colspan=""4""><span>Previous</span>&nbsp;<a href=""javascript:__doPostBack('DataGrid1$ctl09$ctl01','')"" style=""color:#333333;"">Next</a></td>
+	</tr>
+</table>";
+
+			HtmlDiff.AssertAreEqual (expectedFourthPage, gridHtml, "DataGrid Delete");
+		}
+
+		[Test]
+		[NUnit.Framework.Category ("NunitWeb")]
+		public void SelectedIndex ()
+		{
+			WebTest t = new WebTest ("DataGrid.aspx");
+			t.Invoker = PageInvoker.CreateOnInit (DataGrid_OnInit);
+			string html = t.Run ();
+			string gridHtml = HtmlDiff.GetControlFromPageHtml (html);
+			string expectedFirstPage = @"<table cellspacing=""0"" cellpadding=""4"" border=""0"" id=""DataGrid1"" style=""color:#333333;border-collapse:collapse;"">
+	<tr style=""color:White;background-color:#990000;font-weight:bold;"">
+		<td>ID</td><td>Name</td><td>&nbsp;</td><td>&nbsp;</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl02$ctl00','')"" style=""color:White;"">ID</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl02$ctl01','')"" style=""color:White;"">Name</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl02$ctl02','')"" style=""color:White;"">Comment</a></td>
+	</tr><tr style=""color:#333333;background-color:#FFFBD6;"">
+		<td>1</td><td>heh1</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl03$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl03$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>1</td><td>heh1</td><td>Comment 1</td>
+	</tr><tr style=""color:#333333;background-color:White;"">
+		<td>2</td><td>heh2</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl04$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl04$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>2</td><td>heh2</td><td>Comment 2</td>
+	</tr><tr style=""color:#333333;background-color:#FFFBD6;"">
+		<td>3</td><td>heh3</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl05$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl05$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>3</td><td>heh3</td><td>Comment 3</td>
+	</tr><tr style=""color:#333333;background-color:White;"">
+		<td>4</td><td>heh4</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl06$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl06$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>4</td><td>heh4</td><td>Comment 4</td>
+	</tr><tr style=""color:#333333;background-color:#FFFBD6;"">
+		<td>5</td><td>heh5</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl07$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl07$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>5</td><td>heh5</td><td>Comment 5</td>
+	</tr><tr style=""color:White;background-color:#990000;font-weight:bold;"">
+		<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
+	</tr><tr align=""center"" style=""color:#333333;background-color:#FFCC66;"">
+		<td colspan=""4""><span>Previous</span>&nbsp;<a href=""javascript:__doPostBack('DataGrid1$ctl09$ctl01','')"" style=""color:#333333;"">Next</a></td>
+	</tr>
+</table>";
+
+			HtmlDiff.AssertAreEqual (expectedFirstPage, gridHtml, "DataGrid initial Render");
+
+			FormRequest fr = new FormRequest (t.Response, "form1");
+			fr.Controls.Add ("__EVENTTARGET");
+			fr.Controls.Add ("__EVENTARGUMENT");
+			fr.Controls ["__EVENTTARGET"].Value = "Button1";
+			fr.Controls ["__EVENTARGUMENT"].Value = "";
+			t.Request = fr;
+
+			html = t.Run ();
+			gridHtml = HtmlDiff.GetControlFromPageHtml (html);
+			string expectedSecondPage = @"
+        <table cellspacing=""0"" cellpadding=""4"" border=""0"" id=""DataGrid1"" style=""color:#333333;border-collapse:collapse;"">
+	<tr style=""color:White;background-color:#990000;font-weight:bold;"">
+		<td>ID</td><td>Name</td><td>&nbsp;</td><td>&nbsp;</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl02$ctl00','')"" style=""color:White;"">ID</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl02$ctl01','')"" style=""color:White;"">Name</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl02$ctl02','')"" style=""color:White;"">Comment</a></td>
+	</tr><tr style=""color:Navy;background-color:#FFCC66;font-weight:bold;"">
+		<td>1</td><td>heh1</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl03$ctl00','')"" style=""color:Navy;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl03$ctl01','')"" style=""color:Navy;"">Delete</a></td><td>1</td><td>heh1</td><td>Comment 1</td>
+	</tr><tr style=""color:#333333;background-color:White;"">
+		<td>2</td><td>heh2</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl04$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl04$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>2</td><td>heh2</td><td>Comment 2</td>
+	</tr><tr style=""color:#333333;background-color:#FFFBD6;"">
+		<td>3</td><td>heh3</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl05$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl05$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>3</td><td>heh3</td><td>Comment 3</td>
+	</tr><tr style=""color:#333333;background-color:White;"">
+		<td>4</td><td>heh4</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl06$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl06$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>4</td><td>heh4</td><td>Comment 4</td>
+	</tr><tr style=""color:#333333;background-color:#FFFBD6;"">
+		<td>5</td><td>heh5</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl07$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl07$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>5</td><td>heh5</td><td>Comment 5</td>
+	</tr><tr style=""color:White;background-color:#990000;font-weight:bold;"">
+		<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
+	</tr><tr align=""center"" style=""color:#333333;background-color:#FFCC66;"">
+		<td colspan=""4""><span>Previous</span>&nbsp;<a href=""javascript:__doPostBack('DataGrid1$ctl09$ctl01','')"" style=""color:#333333;"">Next</a></td>
+	</tr>
+</table>";
+			HtmlDiff.AssertAreEqual (expectedSecondPage, gridHtml, "DataGrid Selected 1");
+
+			fr = new FormRequest (t.Response, "form1");
+			fr.Controls.Add ("__EVENTTARGET");
+			fr.Controls.Add ("__EVENTARGUMENT");
+			fr.Controls ["__EVENTTARGET"].Value = "Button1";
+			fr.Controls ["__EVENTARGUMENT"].Value = "";
+			t.Request = fr;
+
+			html = t.Run ();
+			gridHtml = HtmlDiff.GetControlFromPageHtml (html);
+			string expectedThirdPage = @"
+        <table cellspacing=""0"" cellpadding=""4"" border=""0"" id=""DataGrid1"" style=""color:#333333;border-collapse:collapse;"">
+	<tr style=""color:White;background-color:#990000;font-weight:bold;"">
+		<td>ID</td><td>Name</td><td>&nbsp;</td><td>&nbsp;</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl02$ctl00','')"" style=""color:White;"">ID</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl02$ctl01','')"" style=""color:White;"">Name</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl02$ctl02','')"" style=""color:White;"">Comment</a></td>
+	</tr><tr style=""color:#333333;background-color:#FFFBD6;"">
+		<td>1</td><td>heh1</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl03$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl03$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>1</td><td>heh1</td><td>Comment 1</td>
+	</tr><tr style=""color:Navy;background-color:#FFCC66;font-weight:bold;"">
+		<td>2</td><td>heh2</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl04$ctl00','')"" style=""color:Navy;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl04$ctl01','')"" style=""color:Navy;"">Delete</a></td><td>2</td><td>heh2</td><td>Comment 2</td>
+	</tr><tr style=""color:#333333;background-color:#FFFBD6;"">
+		<td>3</td><td>heh3</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl05$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl05$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>3</td><td>heh3</td><td>Comment 3</td>
+	</tr><tr style=""color:#333333;background-color:White;"">
+		<td>4</td><td>heh4</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl06$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl06$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>4</td><td>heh4</td><td>Comment 4</td>
+	</tr><tr style=""color:#333333;background-color:#FFFBD6;"">
+		<td>5</td><td>heh5</td><td><a href=""javascript:__doPostBack('DataGrid1$ctl07$ctl00','')"" style=""color:#333333;"">Edit</a></td><td><a href=""javascript:__doPostBack('DataGrid1$ctl07$ctl01','')"" style=""color:#333333;"">Delete</a></td><td>5</td><td>heh5</td><td>Comment 5</td>
+	</tr><tr style=""color:White;background-color:#990000;font-weight:bold;"">
+		<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
+	</tr><tr align=""center"" style=""color:#333333;background-color:#FFCC66;"">
+		<td colspan=""4""><span>Previous</span>&nbsp;<a href=""javascript:__doPostBack('DataGrid1$ctl09$ctl01','')"" style=""color:#333333;"">Next</a></td>
+	</tr>
+</table>";
+
+			HtmlDiff.AssertAreEqual (expectedThirdPage, gridHtml, "DataGrid Selected 2");
+
+		}
+
+		public static void DataGrid_OnInit (Page p) 
+		{
+			if (!p.IsPostBack)
+				MyDataSource.Init ();
+			DataGrid DataGrid1 = (DataGrid)p.FindControl ("DataGrid1");
+			DataGrid1.PageIndexChanged += new DataGridPageChangedEventHandler (DataGrid1_PageIndexChanged);
+			DataGrid1.CancelCommand += new DataGridCommandEventHandler (DataGrid1_CancelCommand);
+			DataGrid1.DeleteCommand += new DataGridCommandEventHandler (DataGrid1_DeleteCommand);
+			DataGrid1.EditCommand += new DataGridCommandEventHandler (DataGrid1_EditCommand);
+			DataGrid1.UpdateCommand += new DataGridCommandEventHandler (DataGrid1_UpdateCommand);
+			DataGrid1.ItemCreated += new DataGridItemEventHandler (DataGrid1_ItemCreated);
+		}
+
+		public static void DataGrid1_ItemCreated (object sender, DataGridItemEventArgs e)
+		{
+			if (e.Item.ItemType == ListItemType.Pager) {
+				e.Item.Cells [0].ColumnSpan = 4;
+			}
+		}
+
+		public static void DataGrid1_PageIndexChanged (object source, DataGridPageChangedEventArgs e) 
+		{
+			DataGrid DataGrid1 = (DataGrid) source;
+			DataGrid1.CurrentPageIndex = e.NewPageIndex;
+			DataGrid1.DataBind ();
+		}
+
+		public static void DataGrid1_EditCommand (object source, DataGridCommandEventArgs e) 
+		{
+			DataGrid DataGrid1 = (DataGrid) source;
+			DataGrid1.EditItemIndex = e.Item.ItemIndex;
+			DataGrid1.DataBind ();
+		}
+
+		public static void DataGrid1_DeleteCommand (object source, DataGridCommandEventArgs e) 
+		{
+			DataGrid DataGrid1 = (DataGrid) source;
+			MyDataSource ds = new MyDataSource ();
+			ds.DeleteItem (e.Item.DataSetIndex);
+			DataGrid1.DataBind ();
+		}
+
+		public static void DataGrid1_UpdateCommand (object source, DataGridCommandEventArgs e) 
+		{
+			DataGrid DataGrid1 = (DataGrid) source;
+			MyDataSource ds = new MyDataSource ();
+			TextBox edittedName = (TextBox) e.Item.Cells [1].Controls [0];
+			ds.UpdateItem (e.Item.DataSetIndex, Int32.Parse (e.Item.Cells [0].Text), edittedName.Text);
+			DataGrid1.EditItemIndex = -1;
+			DataGrid1.DataBind ();
+		}
+
+		public static void DataGrid1_CancelCommand (object source, DataGridCommandEventArgs e) 
+		{
+			DataGrid DataGrid1 = (DataGrid) source;
+			DataGrid1.EditItemIndex = -1;
+			DataGrid1.DataBind ();
+		}
+
+		public class MyDataSource
+		{
+			private static ArrayList _data;
+
+			static MyDataSource () 
+			{
+				Init ();
+			}
+
+			public static void Init ()
+			{
+				_data = new ArrayList ();
+				_data.Add (new MyDataItem (1, "heh1", "Comment 1"));
+				_data.Add (new MyDataItem (2, "heh2", "Comment 2"));
+				_data.Add (new MyDataItem (3, "heh3", "Comment 3"));
+				_data.Add (new MyDataItem (4, "heh4", "Comment 4"));
+				_data.Add (new MyDataItem (5, "heh5", "Comment 5"));
+				_data.Add (new MyDataItem (6, "heh6", "Comment 6"));
+				_data.Add (new MyDataItem (7, "heh7", "Comment 7"));
+				_data.Add (new MyDataItem (8, "heh8", "Comment 8"));
+				_data.Add (new MyDataItem (9, "heh9", "Comment 9"));
+				_data.Add (new MyDataItem (10, "heh10", "Comment 10"));
+			}
+
+			public MyDataSource () 
+			{
+			}
+
+			public ArrayList GetAllItems () 
+			{
+				return _data;
+			}
+
+			public int GetCount () 
+			{
+				return _data.Count;
+			}
+
+			public void UpdateItem (int itemIndex, int id, string name) 
+			{
+				if (itemIndex >= 0 && itemIndex < _data.Count) {
+					MyDataItem item = (MyDataItem) _data [itemIndex];
+					item.Name = name;
+					return;
+				}
+			}
+
+			public void DeleteItem (int p) 
+			{
+				_data.RemoveAt (p);
+			}
+		}
+
+		public class MyDataItem
+		{
+			int _id = 0;
+			string _name = "";
+			string _comment = "";
+
+			public MyDataItem (int id, string name, string comment) 
+			{
+				_id = id;
+				_name = name;
+				_comment = comment;
+			}
+
+			public int ID {
+				get { return _id; }
+			}
+
+			public string Name {
+				get { return _name; }
+				set { _name = value; }
+			}
+
+			public string Comment {
+				get { return _comment; }
+				set { _comment = value; }
+			}
+		}
+
+#endif
+
 		class MyTemplate : ITemplate {
 			string text;
 			public MyTemplate (string text)

+ 46 - 0
mcs/class/System.Web/Test/mainsoft/NunitWebResources/DataGrid.aspx

@@ -0,0 +1,46 @@
+<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MyPage.aspx.cs" Inherits="MyPage" %>
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<script runat="server">
+
+	protected void Button1_Click (object sender, EventArgs e) {
+		DataGrid1.SelectedIndex++;
+	}
+</script>
+
+<html xmlns="http://www.w3.org/1999/xhtml" >
+<head id="Head1" runat="server">
+    <title>Untitled Page</title>
+</head>
+<body>
+    <form id="form1" runat="server">
+    <div><%= MonoTests.stand_alone.WebHarness.HtmlDiff.BEGIN_TAG %>
+        <asp:DataGrid ID="DataGrid1" runat="server" DataSourceID="ObjectDataSource1" DataKeyField="id" AllowPaging="True" AllowSorting="True" CellPadding="4" ForeColor="#333333" GridLines="None" PageSize="5" ShowFooter="True">
+            <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
+            <SelectedItemStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
+            <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" NextPageText="Next"
+                PrevPageText="Previous" />
+            <AlternatingItemStyle BackColor="White" />
+            <ItemStyle BackColor="#FFFBD6" ForeColor="#333333" />
+            <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
+            <Columns>
+                <asp:BoundColumn ReadOnly="True" DataField="ID" HeaderText="ID"></asp:BoundColumn>
+                <asp:BoundColumn DataField="Name" HeaderText="Name"></asp:BoundColumn>
+                <asp:EditCommandColumn CancelText="Cancel" EditText="Edit" UpdateText="Update"></asp:EditCommandColumn>
+                <asp:ButtonColumn CommandName="Delete" Text="Delete"></asp:ButtonColumn>
+            </Columns>
+            <EditItemStyle BackColor="Green" Font-Bold="False" Font-Italic="False" Font-Overline="False"
+                Font-Strikeout="False" Font-Underline="False" />
+        </asp:DataGrid><%= MonoTests.stand_alone.WebHarness.HtmlDiff.END_TAG %>
+        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetAllItems" SelectCountMethod="GetCount" MaximumRowsParameterName="maxRows"
+            TypeName="MonoTests.System.Web.UI.WebControls.DataGridTest+MyDataSource" UpdateMethod="UpdateItem" StartRowIndexParameterName="startIndex" OldValuesParameterFormatString="original_{0}" EnablePaging="False">
+            <UpdateParameters>
+                <asp:Parameter Name="id" Type="Int32" />
+                <asp:Parameter Name="name" Type="String" />
+            </UpdateParameters>
+        </asp:ObjectDataSource>
+        <asp:Button ID="Button1" runat="server" Text="Button" UseSubmitBehavior="false" OnClick="Button1_Click" /></div>
+    </form>
+</body>
+</html>