Procházet zdrojové kódy

2006-10-04 Igor Zelmanovich <[email protected]>

	* GridView.cs: corrected rendering 
	* ContainedTable.cs: added new helper class 
		

svn path=/trunk/mcs/; revision=66218
Igor Zelmanovich před 19 roky
rodič
revize
08d07daabd

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

@@ -1,3 +1,8 @@
+2006-10-04 Igor Zelmanovich <[email protected]>
+
+	* GridView.cs: corrected rendering 
+	* ContainedTable.cs: added new helper class 
+		
 2006-10-03 Igor Zelmanovich <[email protected]>
 
 	* FormView.cs: fixed: 

+ 54 - 0
mcs/class/System.Web/System.Web.UI.WebControls/ContainedTable.cs

@@ -0,0 +1,54 @@
+//
+// System.Web.UI.WebControls.DataControlButton.cs
+//
+// Authors:
+//	Igor Zelmanovich ([email protected])
+//
+// (C) 2006 Mainsoft, Inc (http://www.mainsoft.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_2_0
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace System.Web.UI.WebControls
+{
+	class ContainedTable : Table
+	{
+		WebControl _container;
+
+		public ContainedTable (WebControl container) {
+			_container = container;
+		}
+
+		protected override void AddAttributesToRender (HtmlTextWriter writer) {
+
+			ControlStyle.CopyFrom (_container.ControlStyle);
+
+			base.AddAttributesToRender (writer);
+		}
+	}
+}
+
+#endif

+ 25 - 41
mcs/class/System.Web/System.Web.UI.WebControls/GridView.cs

@@ -66,7 +66,6 @@ namespace System.Web.UI.WebControls
 		DataControlFieldCollection columns;
 		PagerSettings pagerSettings;
 		
-		TableStyle style;
 		TableItemStyle alternatingRowStyle;
 		TableItemStyle editRowStyle;
 		TableItemStyle emptyDataRowStyle;
@@ -410,13 +409,12 @@ namespace System.Web.UI.WebControls
 		[EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
 		public virtual string BackImageUrl {
 			get {
-				object ob = ViewState ["BackImageUrl"];
-				if (ob != null) return (string) ob;
-				return string.Empty;
+				if (ControlStyleCreated)
+					return ((TableStyle) ControlStyle).BackImageUrl;
+				return String.Empty;
 			}
 			set {
-				ViewState ["BackImageUrl"] = value;
-				RequireBinding ();
+				((TableStyle) ControlStyle).BackImageUrl = value;
 			}
 		}
 
@@ -464,13 +462,12 @@ namespace System.Web.UI.WebControls
 		public virtual int CellPadding
 		{
 			get {
-				object o = ViewState ["CellPadding"];
-				if (o != null) return (int) o;
+				if (ControlStyleCreated)
+					return ((TableStyle) ControlStyle).CellPadding;
 				return -1;
 			}
 			set {
-				ViewState ["CellPadding"] = value;
-				RequireBinding ();
+				((TableStyle) ControlStyle).CellPadding = value;
 			}
 		}
 
@@ -479,13 +476,12 @@ namespace System.Web.UI.WebControls
 		public virtual int CellSpacing
 		{
 			get {
-				object o = ViewState ["CellSpacing"];
-				if (o != null) return (int) o;
+				if (ControlStyleCreated)
+					return ((TableStyle) ControlStyle).CellSpacing;
 				return 0;
 			}
 			set {
-				ViewState ["CellSpacing"] = value;
-				RequireBinding ();
+				((TableStyle) ControlStyle).CellSpacing = value;
 			}
 		}
 		
@@ -654,12 +650,12 @@ namespace System.Web.UI.WebControls
 		[DefaultValueAttribute (GridLines.Both)]
 		public virtual GridLines GridLines {
 			get {
-				object ob = ViewState ["GridLines"];
-				if (ob != null) return (GridLines) ob;
+				if (ControlStyleCreated)
+					return ((TableStyle) ControlStyle).GridLines;
 				return GridLines.Both;
 			}
 			set {
-				ViewState ["GridLines"] = value;
+				((TableStyle) ControlStyle).GridLines = value;
 			}
 		}
 
@@ -705,13 +701,12 @@ namespace System.Web.UI.WebControls
 		[DefaultValueAttribute (HorizontalAlign.NotSet)]
 		public virtual HorizontalAlign HorizontalAlign {
 			get {
-				object ob = ViewState ["HorizontalAlign"];
-				if (ob != null) return (HorizontalAlign) ob;
+				if (ControlStyleCreated)
+					return ((TableStyle) ControlStyle).HorizontalAlign;
 				return HorizontalAlign.NotSet;
 			}
 			set {
-				ViewState ["HorizontalAlign"] = value;
-				RequireBinding ();
+				((TableStyle) ControlStyle).HorizontalAlign = value;
 			}
 		}
 
@@ -1091,14 +1086,7 @@ namespace System.Web.UI.WebControls
 		
 		protected virtual Table CreateChildTable ()
 		{
-			Table table = new Table ();
-			table.Caption = Caption;
-			table.CaptionAlign = CaptionAlign;
-			table.CellPadding = CellPadding;
-			table.CellSpacing = CellSpacing;
-			table.HorizontalAlign = HorizontalAlign;
-			table.BackImageUrl = BackImageUrl;
-			return table;
+			return new ContainedTable (this);
 		}
 	
 		protected override int CreateChildControls (IEnumerable data, bool dataBinding)
@@ -1207,10 +1195,9 @@ namespace System.Web.UI.WebControls
 			return dataSource.DataSourceCount;
 		}
 
-		[MonoTODO]
 		protected override Style CreateControlStyle ()
 		{
-			style = new TableStyle (ViewState);
+			TableStyle style = new TableStyle (ViewState);
 			style.GridLines = GridLines.Both;
 			style.CellSpacing = 0;
 			return style;
@@ -1822,20 +1809,16 @@ namespace System.Web.UI.WebControls
 				Page.ClientScript.GetPostBackClientHyperlink (this, "");
 			}
 		}
-		
+
 		protected internal override void Render (HtmlTextWriter writer)
 		{
 			if (EnableSortingAndPagingCallbacks)
-				base.RenderBeginTag (writer);
-			else
-				writer.RenderBeginTag (HtmlTextWriterTag.Div);
+				writer.AddAttribute (HtmlTextWriterAttribute.Id, ClientID);
+			writer.RenderBeginTag (HtmlTextWriterTag.Div);
 
 			RenderGrid (writer);
-			
-			if (EnableSortingAndPagingCallbacks)
-				base.RenderEndTag (writer);
-			else
-				writer.RenderEndTag ();
+
+			writer.RenderEndTag ();
 		}
 		
 		void RenderGrid (HtmlTextWriter writer)
@@ -1843,7 +1826,8 @@ namespace System.Web.UI.WebControls
 			if (table == null)
 				return;
 
-			table.GridLines = GridLines;
+			table.Caption = Caption;
+			table.CaptionAlign = CaptionAlign;
 			table.RenderBeginTag (writer);
 			
 			foreach (GridViewRow row in table.Rows)

+ 1 - 0
mcs/class/System.Web/System.Web.dll.sources

@@ -682,6 +682,7 @@ System.Web.UI.WebControls/CompareValidator.cs
 System.Web.UI.WebControls/CompleteWizardStep.cs
 System.Web.UI.WebControls/CompositeControl.cs
 System.Web.UI.WebControls/CompositeDataBoundControl.cs
+System.Web.UI.WebControls/ContainedTable.cs
 System.Web.UI.WebControls/ContentControlBuilderInternal.cs
 System.Web.UI.WebControls/Content.cs
 System.Web.UI.WebControls/ContentDirection.cs

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

@@ -1,3 +1,7 @@
+2006-10-04 Igor Zelmanovich <[email protected]>
+
+	* GridViewTest.cs: added test
+			
 2006-09-28 Igor Zelmanovich <[email protected]>
 
 	* FormViewTest.cs: removed NotWorking attributes, fixed tests

+ 15 - 9
mcs/class/System.Web/Test/System.Web.UI.WebControls/GridViewTest.cs

@@ -577,11 +577,16 @@ namespace MonoTests.System.Web.UI.WebControls
 		}
 		
 		[Test]
-		public void GridView_CreateChildTable()
-		{
+		public void GridView_CreateChildTable () {
 			PokerGridView g = new PokerGridView ();
-			Assert.IsNotNull (g.DoCreateChildTable (), "CreateChildTable");  
-			Assert.IsTrue (g.DoCreateChildTable() is Table, "CreateChildTable");  
+			g.ID = "PokerGridView";
+			g.Caption = "Caption";
+			g.CaptionAlign = TableCaptionAlign.Right;
+			g.CellPadding = 2;
+			g.CellSpacing = 2;
+			Table t = g.DoCreateChildTable ();
+			Assert.IsNotNull (t, "CreateChildTable#1");
+			Assert.AreEqual (false, t.ControlStyleCreated, "CreateChildTable#2");
 		}
 
 		[Test]
@@ -607,13 +612,13 @@ namespace MonoTests.System.Web.UI.WebControls
 			Assert.AreEqual (DataControlRowState.Normal, gr.RowState, "CreateRow#4");
 		}
 
-		[Test]
+		[Test]
 		[Category ("NotWorking")]
 		public void GridView_GetCallbackResult()
 		{
 			Page page = new Page ();
 			PokerGridView g = new PokerGridView ();
-			page.Controls.Add (g);
+			page.Controls.Add (g);
 			string s = g.doGetCallbackResult ();
 			if (s == null || s == string.Empty) {
 				Assert.Fail ("GetCallbackResult");
@@ -1851,9 +1856,9 @@ namespace MonoTests.System.Web.UI.WebControls
 			if (pageHTML.IndexOf ("EditSuccess") < 0) {
 				Assert.Fail ("EditFail");
 			}
-		}
-
-		[Test]
+		}
+
+		[Test]
 		[Category ("NunitWeb")]
 		public void GridView_PostBackSelect ()
 		{
@@ -2090,3 +2095,4 @@ namespace MonoTests.System.Web.UI.WebControls
 
 #endif
 
+