[Mono-dev] WebControl DataList SelectedIndex and EditItemIndex patch

Jarosław Pawlak jarek.pawlak at gmail.com
Thu Jul 6 05:45:55 EDT 2006


On 6/22/06, Gonzalo Paniagua Javier <gonzalo at novell.com> wrote:
> On Thu, 2006-06-22 at 13:39 +0200, Jarosław Pawlak wrote:
> > Hello
> >
> > On DataList control, when edited item happens to be also selected
> > item, there was a problem, because DataList generated item from
> > SelectedItem template instead of EditItemTemplate.
> > This patch fixes the problem.
>
> Can we also get a test case for this bad behavior?
>
> -Gonzalo
Hello
here it is. Tested on ms.net (passes) and on mono.
============================================
--- DataListTest.cs	(original)
+++ DataListTestMy.cs	(my)
@@ -988,7 +988,40 @@
 				ctrl.Controls.Add (new LiteralControl ("Lalalaa"));
 			}
 		}
-
+        //Some real templates for testing if proper Template was used
+        class ItemTemplate : ITemplate
+        {
+            public void InstantiateIn(Control container)
+            {
+                Label lbl = new Label();
+                lbl.ID = "itemtmpl";
+                container.Controls.Add(lbl);
+            }
+        }
+        class EditItemTemplate : ITemplate
+        {
+            public void InstantiateIn(Control container)
+            {
+                TextBox tb = new TextBox();
+                tb.ID = "eitemtmpl";
+                container.Controls.Add(tb);
+            }
+        }
+        [Test]
+        public void ProperTemplateSelectedIndexEqualsEditIndex()
+        {
+            TestDataList dl = new TestDataList();
+            dl.ItemTemplate = new ItemTemplate();
+            dl.AlternatingItemTemplate = new ItemTemplate();
+            dl.SelectedItemTemplate = new ItemTemplate();
+            dl.EditItemTemplate = new EditItemTemplate();
+            dl.DataSource = GetData(5);
+            dl.SelectedIndex = 0;
+            dl.EditItemIndex = 0;
+            dl.DataBind();
+            object canIGetMyEditItem =
dl.Items[dl.EditItemIndex].FindControl("eitemtmpl");
+            Assert.IsTrue(canIGetMyEditItem != null,
"ProperTemplateSelectedIndexEqualsEditIndex");
+        }
 		[Test]
 		public void NControls3 ()
 		{
@@ -1154,3 +1187,4 @@
 	}
 }

+
============================================


More information about the Mono-devel-list mailing list