CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums

ASP.NET Web Hosting
3 Months Free and Free Setup - ASP.NET Web Hosting



Can Reply:  No Members Can Edit: No Online: Yes
Zone: > NEWSGROUP > Asp.Net Forum > windows_hosting.hosting_open_forum Tags:
Item Type: NewsGroup Date Entered: 5/26/2005 3:08:41 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 12 Views: 40 Favorited: 0 Favorite
13 Items, 1 Pages 1 |< << Go >> >|
fil
Asp.Net User
Retrieve Inline(.aspx) declared controls from Template5/26/2005 3:08:41 PM

0/0

I have a working templated data bound control that I want to take a step further.

<ItemTemplate>

 ... Controls go here

 <asp:panel runat='server' id='panel1'>
 .... Sub controls go here
 </asp:panel>


 <asp:panel runat='server' id='panel2'>
 .... Sub controls go here 
 </asp:panel>
 
 <asp:panel runat='server' id='panel3'>
 .... Sub controls go here
 </asp:panel>


 ... More controls go here

</ItemTemplate>


Basically, how do I retrieve ALL the controls inside of the ItemTemplate tags.
I want to be able to go through these controls and verify the 3 panels exist and have certain sub
controls.

 

Any ideas will be greatly appreciated.

Thanks

WilcoB
Asp.Net User
Re: Retrieve Inline(.aspx) declared controls from Template5/29/2005 10:47:07 AM

0/0

You can handle the ItemCreated event of that control. In the eventhandler you can go through the controls in the created item control (see the event args object passed to the handler). You probably want to do this recursively, because those panels may be children of other controls.


- Wilco Bauwer / http://www.wilcob.com
fil
Asp.Net User
Re: Retrieve Inline(.aspx) declared controls from Template5/31/2005 6:24:30 PM

0/0

That din't work....I ran into the same problem with and without adding functionality to the ItemCreated event.

Here's the problem in a little more detail.

I have a control:

public class Grid : WebControl, INamingContainer, IPostBackEventHandler
{
.........
........
    private GridItem itemTemplate;
.......
.......

}

And I have items that I put in the control(one which is the itemTemplate)

public class GridItem : TableCell, INamingContainer, ITemplate
{
.......
        public void InstantiateIn(Control container)
        {
            if (myPanel != null)
            {
                container.Controls.Add(myPanel);
            }
        }

}


In a test .aspx page I have this:

                <ItemTemplate>

                        <asp:Label runat="server"  text='<%# DataBinder.Eval(Container.DataItem, "title") %>' ID="Label3"/>
                        <asp:Panel runat='server' id='panel'>
                            BLAh
                        </asp:Panel>
                        <asp:TextBox Runat='server' ID="Textbox1"></asp:TextBox>
                </ItemTemplate>


The ItemTemplate property is exposed in the Grid class and as I create items I get the panel out and poulate the MyPanel property of the GridItem.

But when the items are output only the LAST item shows the info from the panel.  How do I get the panel to show up for each item?
Please let me know if this description is not clear.

Any help is greatly appreciated...

WilcoB
Asp.Net User
Re: Retrieve Inline(.aspx) declared controls from Template5/31/2005 9:38:58 PM

0/0

If I understand you correctly, you create 1 GridItem based on the ItemTemplate, and then for each item in your grid you add stuff to the Panel in that grid item you created? If that is the case, then I think you should change that. You probably want to create a GridItem for each item in the data source.

Could you post some code where you actually use the GridItem? That way I know how you are doing it exactly, and provide you with feedback on how it should be.

- Wilco Bauwer / http://www.wilcob.com
fil
Asp.Net User
Re: Retrieve Inline(.aspx) declared controls from Template6/1/2005 12:26:51 PM

0/0

Sure, I will post some code to further explain.  Please allow me some time to actually formulate a question and clean up my code as I have been working on this for a few days now and have tried MANY different approaches.
fil
Asp.Net User
Re: Retrieve Inline(.aspx) declared controls from Template6/1/2005 3:42:43 PM

0/0

I know this is going to be code overload...but here you go.  I have tired to only include the parts I thought were relevant.

<code>
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MSPress.WebControls
{
 /// <summary>
 /// Summary description for TwoLevelDataGrid.
 /// </summary>
    [
    ParseChildren(true),
    DefaultEvent("SelectedIndexChanged"),
    DefaultProperty("DataSource"),
    Designer(typeof(MSPress.WebControls.Design.TreeDataGridDesigner), typeof(IDesigner))
    ]
 public class TreeDataGrid : WebControl, INamingContainer, IPostBackEventHandler
 {
        private static readonly object EventSelectedIndexChanged = new object();
        private static readonly object EventItemCreated = new object();
        private static readonly object EventItemDataBound = new object();
        private static readonly object EventItemCommand = new object();

        public const string SelectCommandName = "Select";
        public const string EditCommandName = "Edit";
        public const string UpdateCommandName = "Update";
        public const string CancelEditCommandName = "Cancel";
        public const string DeleteCommandName = "Delete";

        private bool renderClickSelectScript;
        private DataKeyCollection dataKeys;

        private TreeDataGridItem itemTemplate;
        private TreeDataGridItem editItemTemplate;
        private TreeDataGridItem headerTemplate;
        private TreeDataGridItem footerTemplate;

        private object dataSource;
        private TableItemStyle itemStyle;
        private TableItemStyle editItemStyle;
        private TableItemStyle selectedItemStyle;
        private TableItemStyle headerStyle;
        private TableItemStyle footerStyle;
        private TreeDataGridItemCollection items;
        private TreeDataGridPanelStyle viewStyle;
  
  #region Properties

        [
        Browsable(false),
        DefaultValue(null),
        Description("The template associated with all items"),
        PersistenceMode(PersistenceMode.InnerProperty),
        TemplateContainer(typeof(TreeDataGridItem))
        ]
        public TreeDataGridItem ItemTemplate
        {
            get
            {
                return itemTemplate;
            }
            set
            {
                itemTemplate = value;
            }
        }


        [
        Category("Data"),
        DefaultValue(""),
        Description("The name of the field that contains a key for each item")
        ]
        public virtual string DataKeyField
        {
            get
            {
                string s = (string)ViewState["DataKeyField"];
                return (s == null) ? String.Empty : s;
            }
            set
            {
                ViewState["DataKeyField"] = value;
            }
        }

        [
        Browsable(false),
        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
        ]
        public DataKeyCollection DataKeys
        {
            get
            {
                if (dataKeys == null)
                {
                    dataKeys = new DataKeyCollection(this.DataKeysArray);
                }
                return dataKeys;
            }
        }

        private ArrayList DataKeysArray
        {
            get
            {
                object o = ViewState["DataKeys"];
                if (o == null)
                {
                    o = new ArrayList();
                    ViewState["DataKeys"] = o;
                }
                return (ArrayList)o;
            }
        }

        [
        Category("Data"),
        DefaultValue(""),
        Description("The name of the table within the data source")
        ]
        public virtual string DataMember
        {
            get
            {
                string s = (string)ViewState["DataMember"];
                return (s == null) ? String.Empty : s;
            }
            set
            {
                ViewState["DataMember"] = value;
            }
        }


        [
        Bindable(true),
        Category("Data"),
        DefaultValue(null),
        Description("The data source containing data to be rendered"),
        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
        ]
        public virtual object DataSource
        {
            get
            {
                return dataSource;
            }
            set
            {
                if ((value == null) || (value is IListSource) || (value is IEnumerable))
                {
                    dataSource = value;
                }
                else
                {
                    throw new ArgumentException();
                }
            }
        }


        [
        Browsable(false),
        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
        ]
        public TreeDataGridItemCollection Items
        {
            get
            {
                EnsureChildControls();
                return items;
            }
        }


        [
        Bindable(true),
        Category("Appearance"),
        DefaultValue(1),
        Description("The number of columns in the rendering")
        ]
        public virtual int Columns
        {
            get
            {
                object i = ViewState["Columns"];
                return (i == null) ? 1 : (int)i;
            }
            set
            {
                if (value < 1)
                {
                    throw new ArgumentOutOfRangeException("value");
                }
                ViewState["Columns"] = value;
            }
        }
       
        [
        Category("Behavior"),
        Description("Raised when an item is created")
        ]
        public event TreeDataGridItemEventHandler ItemCreated
        {
            add
            {
                Events.AddHandler(EventItemCreated, value);
            }
            remove
            {
                Events.RemoveHandler(EventItemCreated, value);
            }
        }

        [
        Category("Behavior"),
        Description("Raised when an item has been data-bound")
        ]
        public event TreeDataGridItemEventHandler ItemDataBound
        {
            add
            {
                Events.AddHandler(EventItemDataBound, value);
            }
            remove
            {
                Events.RemoveHandler(EventItemDataBound, value);
            }
        }

 

        [
        Category("Action"),
        Description("Raised when a control within an item raises a Command event")
        ]
        public event TreeDataGridCommandEventHandler ItemCommand
        {
            add
            {
                Events.AddHandler(EventItemCommand, value);
            }
            remove
            {
                Events.RemoveHandler(EventItemCommand, value);
            }
        }
  
  #endregion

        #region Events
       
        public override void DataBind()
        {
            // Data-bound controls implement custom data-binding logic by overriding
            // this method.

            // NOTE: We still want the DataBinding event to fire, so any <%# %> expressions
            //       on this control get evaluated first
            base.OnDataBinding(EventArgs.Empty);

            // Now re-create the new control hierarchy using the assigned data source.
            Controls.Clear();

            // We also want to throw out any view state for children if it exists because
            // we're creating a new hierarchy. And then start tracking changes made
            // during the data-binding process.
            ClearChildViewState();
            TrackViewState();

            CreateControlHierarchy(true);

            // Mark the flag indicating child controls have been created, so that
            // CreateChildControls does not get called.
            ChildControlsCreated = true;
        }
      
  
        protected virtual void OnSelectedIndexChanged(EventArgs e)
        {
            EventHandler handler = (EventHandler)Events[EventSelectedIndexChanged];
            if (handler != null)
            {
                handler(this, null);
            }
        }


        protected virtual void OnItemCreated(TreeDataGridItemEventArgs e)
        {
            TreeDataGridItemEventHandler handler = (TreeDataGridItemEventHandler)Events[EventItemCreated];

            if (handler != null)
            {
                handler(this, null);
            }
        }

       
        protected virtual void OnItemDataBound(TreeDataGridItemEventArgs e)
        {
            TreeDataGridItemEventHandler handler = (TreeDataGridItemEventHandler)Events[EventItemDataBound];
            if (handler != null)
            {
                handler(this, null);
            }
        }

        #endregion

        #region Methods
        protected override void CreateChildControls()
        {
            // If this gets called, we are re-creating children (the items)
            // from view state.
            Controls.Clear();

            // We can create the items if we have view state, so we check for
            // the number of Items we created during a previous request via a
            // call to the DataBind method.
            if (ViewState["Items"] != null)
            {
                CreateControlHierarchy(false);
            }
        }


        protected virtual void CreateControlHierarchy(bool useDataSource)
        {
            IEnumerable dataSource = null;
 
            int itemCount = 0;
            this.items = null;

            ArrayList dataKeysArray = DataKeysArray;
            string dataKeyField = null;

            if (useDataSource)
            {
                dataSource = GetDataSource();

                dataKeysArray.Clear();
                dataKeyField = DataKeyField;
            }
            else
            {
                dataSource = new object[(int)ViewState["Items"]];
            }

            if (dataSource != null)
            {
                Table outerTable = new Table();
                Controls.Add(outerTable);

                TreeDataGridItem headerItem = null;
                TreeDataGridItem footerItem = null;

                if (this.headerTemplate != null)
                {
                    TableRow headerRow = new TableRow();
                    outerTable.Rows.Add(headerRow);
                    headerItem = CreateTreeDataGridItem(headerRow, -1, TreeDataGridItemType.Header, null, useDataSource);
                }

                TableRow bodyRow = new TableRow();
                outerTable.Rows.Add(bodyRow);

                TableCell bodyCell = new TableCell();
                bodyRow.Cells.Add(bodyCell);

                TreeDataGridPanel viewPanel = new TreeDataGridPanel();
                bodyCell.Controls.Add(viewPanel);

                TreeDataGridTable innerTable = CreateTreeDataGridTable();
                viewPanel.Controls.Add(innerTable);

                TableRow itemsRow = new TableRow();
                innerTable.Rows.Add(itemsRow);

                int editIndex = EditIndex;
                int selectedIndex = SelectedIndex;

                int itemIndex = 0;

                foreach (object dataItem in dataSource)
                {
                    TreeDataGridItemType itemType = TreeDataGridItemType.Item;

                    if (itemIndex == editIndex)
                    {
                        itemType |= TreeDataGridItemType.EditItem;
                    }
                    if (itemIndex == selectedIndex)
                    {
                        itemType |= TreeDataGridItemType.SelectedItem;
                    }

                    CreateTreeDataGridItem(itemsRow, itemIndex, itemType, dataItem, useDataSource);
                    itemIndex++;
                    itemCount++;

                    if (useDataSource && (dataKeyField.Length != 0))
                    {
                        dataKeysArray.Add(DataBinder.GetPropertyValue(dataItem, dataKeyField));
                    }
                }

                if (this.footerTemplate != null)
                {
                    TableRow footerRow = new TableRow();
                    outerTable.Rows.Add(footerRow);
                    CreateTreeDataGridItem(footerRow, -1, TreeDataGridItemType.Footer, null, useDataSource);
                }

                this.items = CreateTreeDataGridItemCollection(itemsRow.Cells, headerItem, footerItem);
            }

            if (useDataSource)
            {
                ViewState["Items"] = itemCount;
            }

        }


        protected override Style CreateControlStyle()
        {
            // Because TreeDataGrid renders an HTML table, an instance of
            // a TableStyle is used as the control style.
            TableStyle style = new TableStyle(ViewState);

            // This is also the right spot to initialize the style
            style.CellSpacing = 0;

            return style;
        }


        protected virtual TreeDataGridItem CreateTreeDataGridItem(int itemIndex, TreeDataGridItemType itemType)
        {
            TreeDataGridItem item = new TreeDataGridItem(itemIndex, itemType, null);

            item.ChildColumns.Add (ItemTemplate);

            return item;
            //return new TreeDataGridItem(itemIndex, itemType, this.ItemTemplate.TreeHeader);
        }
       
       
        private TreeDataGridItem CreateTreeDataGridItem(TableRow rowContainer, int itemIndex, TreeDataGridItemType itemType, object dataItem, bool dataBind)
        {
            TreeDataGridItem item = CreateTreeDataGridItem(itemIndex, itemType);
           
            TreeDataGridItemEventArgs e = new TreeDataGridItemEventArgs(item);

            TreeDataGridItem template = GetTemplateForItem(item);
            if (template != null)
            {
                template.InstantiateIn(item);
            }

            OnItemCreated(e);
            rowContainer.Cells.Add(item);

            if (dataBind)
            {
                item.DataItem = dataItem;
                item.DataBind();

                OnItemDataBound(e);
            }

            return item;
        }


        protected virtual TreeDataGridItemCollection CreateTreeDataGridItemCollection(TableCellCollection cells, TreeDataGridItem headerItem, TreeDataGridItem footerItem)
        {
            return new TreeDataGridItemCollection(cells, headerItem, footerItem);
        }
       

        protected virtual TreeDataGridTable CreateTreeDataGridTable()
        {
            return new TreeDataGridTable();
        }

       
        protected virtual TreeDataGridItem GetTemplateForItem(TreeDataGridItem item)
        {
            TreeDataGridItem template = null;
           
            switch (item.ItemType)
            {
                case TreeDataGridItemType.Header:
                    template = this.headerTemplate;
                    break;
                case TreeDataGridItemType.Footer:
                    template = this.footerTemplate;
                    break;
                default:
                    template = this.itemTemplate;
                    if ((item.ItemType & TreeDataGridItemType.EditItem) != 0)
                    {
                        if (this.editItemTemplate != null)
                        {
                            template = this.editItemTemplate;
                        }
                    }
                    break;
            }
            return template;
        }
       

        protected override bool OnBubbleEvent(object sender, EventArgs e)
        {
            TreeDataGridCommandEventArgs lce = e as TreeDataGridCommandEventArgs;

            if (lce != null)
            {
                OnItemCommand(lce);

                if (lce.CommandType == TreeDataGridCommandType.Select)
                {
                    int oldSelectedIndex = SelectedIndex;
                    if (oldSelectedIndex != lce.Item.ItemIndex)
                    {
                        SelectedIndex = lce.Item.ItemIndex;
                        OnSelectedIndexChanged(EventArgs.Empty);
                    }
                }
                return true;
            }
            return false;
        }

       
        protected virtual void OnItemCommand(TreeDataGridCommandEventArgs e)
        {
            TreeDataGridCommandEventHandler handler = (TreeDataGridCommandEventHandler)Events[EventItemCommand];
            if (handler != null)
            {
                handler(this, null);
            }
        }
       
       
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
        }
       
       
        protected virtual void PrepareControlHierarchyForRendering()
        {
        }


        protected override void Render(HtmlTextWriter writer)
        {
            // Applying styles to the control hierarchy and then render it out.

            // NOTE: Styles are applied as late as the render time.
            //       a) User can change styles after calling DataBind.
            //       b) Changes made to items during style application do not
            //          contribute to the view state. This control manages the
            //          state for styles, so having items manage it as well would
            //          be redundant.
            PrepareControlHierarchyForRendering();

            // NOTE: We don't render out tags corresponding to TreeDataGrid itself.
            //       We need to render its contents only. Therefore instead of calling
            //       base.Render, we call RenderContents.
            RenderContents(writer);
        }
}

 

 

 

 

 

 

 

using System;
using System.Collections;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MSPress.WebControls
{
 /// <summary>
 /// Summary description for TreeDataGridItem.
 /// </summary>
    [
    ParseChildren(true),
    ToolboxItem(false)
    ]
 public class TreeDataGridItem : TableCell, INamingContainer, ITemplate
 {
        private int itemIndex;
        private object dataItem;
        private TreeDataGridItemType itemType;

        private TreeDataGridChildren childColumns = new TreeDataGridChildren();
       
        public TreeDataGridItem()
        {
        }

        public TreeDataGridItem(int itemIndex, TreeDataGridItemType itemType, TreeDataGridPanel t)
        {
            this.itemIndex = itemIndex;
            this.itemType = itemType;

            if (t != null)
            {
                treeHeader = t;
                //throw new Exception("Populate the header");
            }
        }


        #region Properties

        public TreeDataGridChildren ChildColumns
        {
            get
            {
                return childColumns;
            }
            set
            {
                childColumns = value;
            }
        }

        public WebControl ChildColumn
        {
            get
            {
                return null;
            }
            set
            {
                childColumns.Add(value);
            }
        }
       
       
        public virtual object DataItem
        {
            get
            {
                return this.dataItem;
            }
            set
            {
                this.dataItem = value;
            }
        }

        public int ItemIndex
        {
            get
            {
                return this.itemIndex;
            }
        }

        public virtual TreeDataGridItemType ItemType
        {
            get
            {
                return this.itemType;
            }
        }
       
        public TreeDataGridPanel TreeHeader
        {
            get
            {
                return treeHeader;
            }
            set
            {
                treeHeader = value;
            }
        }

        #endregion

        protected override bool OnBubbleEvent(object sender, EventArgs e)
        {
            CommandEventArgs ce = e as CommandEventArgs;
           
            if (ce != null)
            {
                TreeDataGridCommandEventArgs lce = new TreeDataGridCommandEventArgs(this, sender, ce);
                RaiseBubbleEvent(this, lce);

                return true;
            }
            return false;
        }

        public virtual void ResetItemType(TreeDataGridItemType newItemType)
        {
            this.itemType = newItemType;
        }
        #region ITemplate Members

        public void InstantiateIn(Control container)
        {       
            // TODO:  Add TreeDataGridItem.InstantiateIn implementation
            //Literal l = new Literal();
            //l.Text = "testing";
            //container.Controls.Add(l);

            //if (treeHeader != null)
            //{
                //container.Controls.Add(treeHeader);
            //}
           
            if (this.childColumns != null)
            {
           
                foreach(WebControl child in childColumns)
                {
                    container.Controls.Add(child);
                }
            }
           
            EnsureChildControls();
        }
       
        protected override void Render(HtmlTextWriter writer)
        {
            this.CreateChildControls();
            base.Render (writer);
        }


        #endregion

        #region IEnumerable Members

        public IEnumerator GetEnumerator()
        {
            // TODO:  Add TreeDataGridItem.GetEnumerator implementation
            return null;
        }

        #endregion
    }
   
    public class TreeDataGridChildren : CollectionBase
    {
        public virtual void Add(WebControl child)
        {
            this.List.Add(child);
        }
       
        public virtual WebControl this[int index]
        {
            get
            {
                return (WebControl)this.List[index];
            }
        }
    }
}

</code>


This code is based from:

Developing Microsoft ASP.NET Server Controls and Components
By Nikhil Kothari, Vandana Datje

Here is what's going on.  First, the DataBind method gets called.  This method then calls CreateControlHierarchy.
CreateControlHierarchy does the actual looping of the items in the datasource and creates a TreeDataGridItem per item in the datasource. 

After these methods run, the overriden Render method gets called.  Which in turn calls the TreeDataGridItem.Render().

This is what is displayed:

   <table cellspacing="4" cellpadding="0" border="0" style="border-width:0px;height:100%;width:100%;">
      <tr><td></td></tr>
      <tr><td></td></tr>
    .........MORE IDENTICAL ELEMENTS HERE .........
      <tr><td></td></tr>
      <tr><td></td></tr>
      <tr>
         <td>
            <span id="listView1__ctl20_Label2">Straight Talk About Computers</span>
            <div>      
                                BLAh
     </div>
     <input name="listView1:_ctl20:Textbox2" type="text" id="listView1__ctl20_Textbox2" />
         </td>
      </tr>
   </table>

I can seem to figure out why it work only for the last item! :)

Please let me know if there is an easier way to do this.  Like I said all I want to do is add any number of controls in the .ASPX page and have them displayed per every item in the data source.  Of course, once this is done I will wire up any server side functionality for the mentioned controls.

WilcoB
Asp.Net User
Re: Retrieve Inline(.aspx) declared controls from Template6/1/2005 4:32:41 PM

0/0

I haven't studied all code, but I think the problem lies in the fact that you are adding the controls in the childColumns collection to the container control in the TreeDataGridItem class (see the InstantiateIn method). Try replacing the implementation with something like this:


public void InstantiateIn(Control container)
{
&nbsp;&nbsp;&nbsp; container.Controls.Add(new LiteralControl("&lt;p&gt;Test&lt;/p&gt;"));
}


This should make sure that a new control is added to each "container". For at least each item in your data source, you should see Test.

Let me know if this is indeed true (and thus the basis of your problem). In that case I will elaborate and help look for a solution to that problem; otherwise I'll look further to see if I overlooked something.

- Wilco Bauwer / http://www.wilcob.com
fil
Asp.Net User
Re: Retrieve Inline(.aspx) declared controls from Template6/1/2005 5:03:13 PM

0/0

Yes this is true.....In the TreeDataGridItem.InstantiateIn method when I add the literal in the code-behind I will get that literal for each item in the data source.

As you can see, I attempted to do the following:

            if (this.childColumns != null)
            {           
                foreach(WebControl child in childColumns)
                {
                    container.Controls.Add(child);
                }
            }

For each item, the InstantiateIn method is called and the for loop runs.... but only the last item gets displayed. 

I figure that since I do not create a NEW instance every time the InstantiateIn method is called.....the added child controls all reference one set of controls.  Thus, when the last item in the data source updates the set of controls we see those changes.
WilcoB
Asp.Net User
Re: Retrieve Inline(.aspx) declared controls from Template6/1/2005 5:44:43 PM

0/0

 fil wrote:
...
I figure that since I do not create a NEW instance every time the InstantiateIn method is called.....the added child controls all reference one set of controls.  Thus, when the last item in the data source updates the set of controls we see those changes.


This is correct. A control can/should only be participating in 1 control collection. When a control is added to 1 control collection, and you also try to add it to another collection, the control will be removed from its first collection and finally only be a child of the second collection. This is exactly what you are experiencing: for each new item, you are basically "moving" the child colums from 1 item to another, until you reached the last data item.

However, from this code I can not see where elements are added to the the childControls collection of the ItemTemplate. So let me assume that there is some other code that is not posted which does this (or I overlooked something).

If you are declaratively defining the template, then variables like itemTemplate should be instantiated for you. All you should have to do is to call its InstantiateIn method and pass a control (a TreeDataGridItem in your case) which should represent the data item in the layout defined by the item template. The item template will then take care of creating a new panel, etc. (whatever you placed in the itemtemplate) for each item and add it to the control you passed to the instantiate in method.

If you need to programmatically define the item template (or any other template): let me know how you are doing that right now so I can provide you with specific feedback.

- Wilco Bauwer / http://www.wilcob.com
fil
Asp.Net User
Re: Retrieve Inline(.aspx) declared controls from Template6/1/2005 6:12:55 PM

0/0

well, the ChildControls are added in the .aspx through the exposed ItemTemplate property(Which itself, a TreeDataGridItem, contains an exposed property called ChildColumns). 

Every time a I create a new TreeDataGridItem I call the following method(which is a little diff't from a previous post):

        protected virtual TreeDataGridItem CreateTreeDataGridItem(int itemIndex, TreeDataGridItemType itemType)
        {
            TreeDataGridItem item = new TreeDataGridItem(itemIndex, itemType, null);

            item.ChildColumns.Add (ItemTemplate.ChildColumns);

            return item;
        }


Basically, I take what was defined in the .aspx and add the child controls(from ItemTemplate.ChildColumns) to the newly created TreeDataGridItem.


I will attempt to change the code based on your recommendations.  Plus, I currently do not see a need to programmatically define the item template.

fil
Asp.Net User
Re: Retrieve Inline(.aspx) declared controls from Template6/1/2005 8:50:30 PM

0/0

I added another tag to the .aspx

<TreeDataGridItem>
..........
<TreeDataGridItem>

and the following Parser error occurs.

    Type 'MSPress.WebControls.TreeDataGrid' does not have a property named 'TreeDataGridItem'.

 

So, I decided to change the ItemTemplate property and its corresponding variable to:

 private ITemaplte itemTemplate;

        [
        Browsable(false),
        DefaultValue(null),
        Description("The template associated with all items"),
        PersistenceMode(PersistenceMode.InnerProperty),
        TemplateContainer(typeof(TreeDataGridItem))
        ]
        public ITemplate ItemTemplate
        {
            get
            {
                return itemTemplate;
            }
            set
            {
                itemTemplate = value;
            }
        }

Of course there were a few other places that needed to change from TreeDataGridItem to ITemplate
but it works as you described. 


But there is still an issue.  Following is the .aspx for just the ItemTemplate


<ItemTemplate>
   <asp:Label runat="server"  text='<%# DataBinder.Eval(Container.DataItem, "title") %>' ID="lbl"/>
   <asp:Panel Runat='server' ID='panel'>
      BLAh
   </asp:Panel>
   <asp:TextBox Runat='server' ID="txt"></asp:TextBox>
  
   <ChildColumns>
      <asp:Label runat="server"  text='<%# DataBinder.Eval(Container.DataItem, "title") %>' ID="lblInner"/>
      <asp:Button Runat='server' ID='btn'></asp:Button>                                           
   </ChildColumns>
</ItemTemplate>

 

Well, I no longer get the ChildColumns property populated(which I did before) but the label and button inside are correctly rendered.

I tried the ChildColumns because basically I want to define 3 sub-sections
inside the ItemTemplate using either panels, CollectionBase derived class, or any other way imagiable.

I want to first verify the sub-sections exist. Then in the code-behind append, to what is defined in the .aspx, distinct controls to each sub-section

Any ideas?

WilcoB
Asp.Net User
Re: Retrieve Inline(.aspx) declared controls from Template6/1/2005 9:46:56 PM

0/0

 fil wrote:
..
Well, I no longer get the ChildColumns property populated(which I did before) but the label and button inside are correctly rendered.

I tried the ChildColumns because basically I want to define 3 sub-sections
inside the ItemTemplate using either panels, CollectionBase derived class, or any other way imagiable.

I want to first verify the sub-sections exist. Then in the code-behind append, to what is defined in the .aspx, distinct controls to each sub-section

Any ideas?



You can not set/add things to the ChildControls of the template declaratively (and you shouldn't want to). I don't know exactly why you want to store a separate collection of child columns, but you can achieve such thing by just having another property on your main control class (the grid). Your markup would then look something like:

<ItemTemplate>
    <Pretty much what you had here.>
</ItemTemplate>
<ChildColumns>
    <asp:Label ... /> etc
</ChildColumns>

However, this won't allow you to add those controls to each item template instance. If you want that, you could probably try and create a ChildColumns control (instead of a collection). You could then go through the controls of each item template instance and check of what type a control is. This "solution" would allow you to have multiple ChildColumns controls, though.

- Wilco Bauwer / http://www.wilcob.com
fil
Asp.Net User
Re: Retrieve Inline(.aspx) declared controls from Template6/13/2005 7:39:36 PM

0/0

Just a follow-up.  I guess I was trying to0 hard and not trying to make the project easy.  I found another way to do the project that is alot more user friendly.  BTW thanks for all the help.


13 Items, 1 Pages 1 |< << Go >> >|


Free Download:


Web:
Cutting Edge: Data Repeater Controls in ASP.NET These child controls can be defined within an inline template or a user control ... In general, Eval is more flexible as it can retrieve both individual and ...
CodeProject: Using the ATL OLE DB Consumer Templates on the Pocket ... Following the style of atldbcli.h, I implemented the whole class inline: ... Now , we can start retrieving information from the row set using the ...
ASP.NET Using the DataList and Repeater, Datagrid Controls Also keep in mind that all these controls are also known as the templated controls since their design is based on templates. Repeator control is used when ...
ASP.Net Interview Question,Interview Question,.Net,Question,Answer ... NET Page Directives and for inline CSS style attributes within a page. .... Server controls are declared within an .aspx file using custom tags or intrinsic ...
Scott on Writing Retrieving viewstate values from dyamically created server controls within a ..... and handled the Event in my aspx pages to bind the data to the dropdown. ...
Your Own Guestbook In ASP.NET | WebProNews In line 27 I have only implemented a reset button. This is all and nothing more has to be done in the webform. If you run the guestbook.aspx, you should see ...
13. Web Application Development Net web controls whereas the application logic contains all the programming .... Inline ASPX code using C# is a safe way to write and experience ASPX hosted ...
Building ASP.NET Web Server Controls using XML and XSLT: ASP Alliance In most cases, server controls are very useful in ASP. ... the XML and XSLT in database side and use a caching technique to retrieve the XSLT template. ...
ASP.NET 2.0 MasterPages and FindControl() - Rick Strahl's Web Log I have declared the CodeFileBaseClass in your @ Page directive; ..... We want to dynamically load the User Controls in the Panel in ASPX page when tab items ...
Content Page Type Customized pages—template pages that a user has modified—are stored in the ... That is, in-line server logic declared within SharePoint content pages is ...












localization comes when?

multiple projects and pa development

dnn 308 issue: membership - user gets added to dnn before being added through membership provider

trying to create a web service to register new users ... where to put it?

please help. site always goes back to home.

a question about solpartmenu - jhenning are you there?

limiting page width

news article 1.0 y2k4 problem and patch

error while installing forum module in dotnetnuke

creating a subscription based site

help with dnn requirements

invalid host rights?

missing rich text editor toolbar in 2.1.2

submit to google up and quit working for me

skin/container: how to add first, next, previous, last links?

online payment processing - newbie help

webhost4life

page cannot be found

webstone shadow error in 2.1.2

clr stored procedures for dnn ?

need help with multi-page modules.

faq module, can it default to expand all?

installing dnn with sql express 2005 db

initializeobject and extending userinfo coding question

item has already been added. key in dictionary: "literal1" key being added: "literal1"

why does 100% css desing fail in dnn? (no tables)

keyword replacement in html/text module?

timezone issues in dnn 3.1.1

error: host settings is currently unavailable.

dnn logo usage

  Privacy | Contact Us
All Times Are GMT