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0aW9uIGFzIG5lc3RlZCBpbm5lciB0YWdzPw0KDQogDQoN Cl9fDQpBbmR5IFNtaXRoDQoNCg=
|
|
| |
| |
| John John |
hello the following sample should help you... It does also answer to the RE: [aspngcontrolscs] collection property in usercontrol question I think...
//---------------------------------------------------------------- // Copyright (C) 2002 Me // All rights reserved. // <author>John Knipper ( <mailto:Click here to reveal e-mail address)> Click here to reveal e-mail address)</author> // <creationdate>01/04/2002</creationdate> // <helpedby>Thanks to Vandana Datye</helpedby> //---------------------------------------------------------------- using System; using System.Collections; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;
using System.ComponentModel; using System.ComponentModel.Design; using System.Drawing; using System.Drawing.Design;
namespace CustomControls { public class Employee { private String name; private String title;
public Employee():this ("",""){}
public Employee (String name, String title) { this.name = name; this.title = title; } [ NotifyParentProperty(true) ] public String Name { get { return name; } set { name = value; } }
[ NotifyParentProperty(true) ] public String Title { get { return title; } set { title = value; } } }
[DefaultProperty("Item")] public class EmployeeCollection : System.Collections.CollectionBase { public void Add(Employee anEmployee) { List.Add(anEmployee); } public void Remove(int index) { // Check to see if there is an Employee at the supplied index. if (index < Count - 1 && index > 0) { List.RemoveAt(index); } } public Employee Item(int Index) { // The appropriate item is retrieved from the List object and // explicitly cast to the Employee type, then returned to the // caller. return (Employee) List[Index]; } }
public class EmployeeCollectionEditor : CollectionEditor {
public EmployeeCollectionEditor(Type type) : base(type) { }
protected override Type CreateCollectionItemType() { return typeof(Employee); //you may need to use the fully qualified name of the type } }
[ ParseChildren(true, "Employees"), //needed by the page parser PersistChildren(false) // Needed by the designer ] public class CollectionPropertyControl : Control { //private ArrayList employees = new ArrayList(); private EmployeeCollection employees = new EmployeeCollection();
[ Editor(typeof(EmployeeCollectionEditor), typeof(UITypeEditor)), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), NotifyParentProperty(true), PersistenceMode(PersistenceMode.InnerDefaultProperty) ] public EmployeeCollection Employees { get { return employees; } }
protected override void CreateChildControls() { Table table = new Table(); TableRow htr = new TableRow();
TableHeaderCell hcell1 = new TableHeaderCell(); hcell1.Text = "Name"; htr.Cells.Add(hcell1);
TableHeaderCell hcell2 = new TableHeaderCell(); hcell2.Text = "Title"; htr.Cells.Add(hcell2);
foreach (Employee employee in Employees) { TableRow tr = new TableRow();
TableCell cell1 = new TableCell(); cell1.Text = employee.Name; tr.Cells.Add(cell1);
TableCell cell2 = new TableCell(); cell2.Text = employee.Title; tr.Cells.Add(cell2);
table.Rows.Add(tr); } Controls.Add(table); } } }
-----Original Message----- From: Andy Smith [mailto:Click here to reveal e-mail address] Sent: dimanche 4 août 2002 02:19 To: aspngcontrolscs Subject: collection property's items in inner tags
I have a control that I want to have put it's Settings collection property as nested inner tags. I thought I had put all the right attributes on the control, but it's not saving the collection at all.
is there anything more I have to do beyond this stuff?
[ ProvideProperty("DefaultButton",typeof(Control)), ParseChildren(true,"Settings"), PersistChildren(false) ] public class DefaultButtons : System.Web.UI.Control, IExtenderProvider {
...
[ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), PersistenceMode(PersistenceMode.InnerDefaultProperty) ] public DefaultButtonSettingCollection Settings { get { return settings; } }
why isn't my control saving the Settings collection as nested inner tags?
__ Andy Smith
|
|
| |
|
| |
| Andy Smith |
I tried implementing your example in my control, and it is still not writing the collection to the page. If you or anybody could take a look at my code, i'd really appreciate it. the full project source is here: http://www.metabuilders.com/betatools/defaultbuttons.zip
thanks for any help in this area. I really apprciate it.
__ Andy Smith Keyboard Jockey #3a7-2.78.1
-----Original Message----- From: John John [mailto:Click here to reveal e-mail address] Sent: Monday, August 05, 2002 3:21 AM To: aspngcontrolscs Subject: [aspngcontrolscs] RE: collection property's items in inner tags
hello the following sample should help you... It does also answer to the RE: [aspngcontrolscs] collection property in usercontrol question I think...
//---------------------------------------------------------------- // Copyright (C) 2002 Me // All rights reserved. // <author>John Knipper ( <mailto:Click here to reveal e-mail address)> Click here to reveal e-mail address)</author> // <creationdate>01/04/2002</creationdate> // <helpedby>Thanks to Vandana Datye</helpedby> //---------------------------------------------------------------- using System; using System.Collections; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;
using System.ComponentModel; using System.ComponentModel.Design; using System.Drawing; using System.Drawing.Design;
namespace CustomControls { public class Employee { private String name; private String title;
public Employee():this ("",""){}
public Employee (String name, String title) { this.name = name; this.title = title; } [ NotifyParentProperty(true) ] public String Name { get { return name; } set { name = value; } }
[ NotifyParentProperty(true) ] public String Title { get { return title; } set { title = value; } } }
[DefaultProperty("Item")] public class EmployeeCollection : System.Collections.CollectionBase { public void Add(Employee anEmployee) { List.Add(anEmployee); } public void Remove(int index) { // Check to see if there is an Employee at the supplied index. if (index < Count - 1 && index > 0) { List.RemoveAt(index); } } public Employee Item(int Index) { // The appropriate item is retrieved from the List object and // explicitly cast to the Employee type, then returned to the // caller. return (Employee) List[Index]; } }
public class EmployeeCollectionEditor : CollectionEditor {
public EmployeeCollectionEditor(Type type) : base(type) { }
protected override Type CreateCollectionItemType() { return typeof(Employee); //you may need to use the fully qualified name of the type } }
[ ParseChildren(true, "Employees"), //needed by the page parser PersistChildren(false) // Needed by the designer ] public class CollectionPropertyControl : Control { //private ArrayList employees = new ArrayList(); private EmployeeCollection employees = new EmployeeCollection();
[ Editor(typeof(EmployeeCollectionEditor), typeof(UITypeEditor)), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), NotifyParentProperty(true), PersistenceMode(PersistenceMode.InnerDefaultProperty) ] public EmployeeCollection Employees { get { return employees; } }
protected override void CreateChildControls() { Table table = new Table(); TableRow htr = new TableRow();
TableHeaderCell hcell1 = new TableHeaderCell(); hcell1.Text = "Name"; htr.Cells.Add(hcell1);
TableHeaderCell hcell2 = new TableHeaderCell(); hcell2.Text = "Title"; htr.Cells.Add(hcell2);
foreach (Employee employee in Employees) { TableRow tr = new TableRow();
TableCell cell1 = new TableCell(); cell1.Text = employee.Name; tr.Cells.Add(cell1);
TableCell cell2 = new TableCell(); cell2.Text = employee.Title; tr.Cells.Add(cell2);
table.Rows.Add(tr); } Controls.Add(table); } } }
-----Original Message----- From: Andy Smith [mailto:Click here to reveal e-mail address] Sent: dimanche 4 août 2002 02:19 To: aspngcontrolscs Subject: collection property's items in inner tags
I have a control that I want to have put it's Settings collection property as nested inner tags. I thought I had put all the right attributes on the control, but it's not saving the collection at all.
is there anything more I have to do beyond this stuff?
[ ProvideProperty("DefaultButton",typeof(Control)), ParseChildren(true,"Settings"), PersistChildren(false) ] public class DefaultButtons : System.Web.UI.Control, IExtenderProvider {
...
[ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), PersistenceMode(PersistenceMode.InnerDefaultProperty) ] public DefaultButtonSettingCollection Settings { get { return settings; } }
why isn't my control saving the Settings collection as nested inner tags?
__ Andy Smith
|
|
| |
|
|
|
|
|