Treeview in combobox can not be found

6 posts, 0 answers
  1. Mario
    Mario avatar
    25 posts
    Member since:
    Jan 2012

    Posted 08 Apr 2012 Link to this post

    Hello,
    I have a Treeview in a related ComboBox.
    <telerik:GridTemplateColumn DataField="LayoutTypeID"
        FilterControlAltText="Filter LayoutTypeID column" HeaderText="Layout Type"
        UniqueName="LayoutTypeID">
        <EditItemTemplate>
            <telerik:RadComboBox ID="LayoutTypeIDRadComboBox" runat="server"
                DataSourceID="ODSLayoutTypes"
                DataTextField="TypeName"
                DataValueField="TypeID"
                onselectedindexchanged="LayoutTypeIDRadComboBox_SelectedIndexChanged"
                AutoPostBack="true"
                SelectedValue='<%# Bind("LayoutTypeID") %>'>
            </telerik:RadComboBox>
        </EditItemTemplate>
        <ItemTemplate>
            <asp:Label ID="LayoutTypeIDLabel" runat="server"
                Text='<%# Eval("LayoutTypeID") %>'></asp:Label>
        </ItemTemplate>
    </telerik:GridTemplateColumn>
    <telerik:GridTemplateColumn DataField="LayoutID"
        FilterControlAltText="Filter column1 column" HeaderText="Layout"
        UniqueName="LayoutID">
        <EditItemTemplate>
            <telerik:RadComboBox ID="LayoutIDRadComboBox"
                runat="server" Culture="de-DE"
                <ItemTemplate>
                    <div id="div1">
                        <telerik:RadTreeView ID="RTVLayouts"
                            runat="server"                                                                     
                            onnodedatabound="RTVLayouts_NodeDataBound" >
                        </telerik:RadTreeView>
                    </div>
                </ItemTemplate>                                                    
            </telerik:RadComboBox>
        </EditItemTemplate>
        <ItemTemplate>
            <asp:Label ID="LayoutIDLabel" runat="server" Text='<%# Eval("LayoutID") %>'></asp:Label>
        </ItemTemplate>
    </telerik:GridTemplateColumn>

    protected void LayoutTypeIDRadComboBox_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        RadComboBox RCBLayoutTypes = sender as RadComboBox;
        GridEditableItem item = RCBLayoutTypes.NamingContainer as GridEditableItem;
     
        RadComboBox RCBLayouts = item.FindControl("LayoutIDRadComboBox") as RadComboBox;
     
        int layoutTypeID = 0;
        try
        {
            layoutTypeID = Convert.ToInt32(e.Value);
        }
        catch
        {
            layoutTypeID = 0;
        }
     
        LoadLayoutsForTreeView(layoutTypeID.ToString(), RCBLayouts);
    }
     
    protected void LoadLayoutsForTreeView(string LayoutTypesID, RadComboBox rcbl)
    {
     
        if (LayoutTypesID != string.Empty)
        {
            //rcbSelectLayout.ClearSelection();
            LayoutsBLL lbll = new LayoutsBLL();
            RadTreeView rtv = (rcbl.Items[0].FindControl("RTVLayouts")) as RadTreeView;
            rtv.DataSource = lbll.GetLayoutsByLayoutTypes(Convert.ToInt32(LayoutTypesID));
            rtv.DataValueField = "LayoutID";
            rtv.DataTextField = "LayoutName";
            rtv.DataFieldID = "LayoutID";
            rtv.DataFieldParentID = "ParentID";
            rtv.DataBind();          
        }
     
    }


    Treeview in combobox can not be found. I get an ArgumentOutOfRangeException - Items count is 0.

    Best regards
    Reiner
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 09 Apr 2012 Link to this post

    Hello Mario,

    Please use below code snippet to avoid this error.
    protected void LoadLayoutsForTreeView(string LayoutTypesID, RadComboBox rcbl)
        {
            if (rcbl.Items.Count > 0)
            {
                RadTreeView rtv = (rcbl.Items[0].FindControl("RTVLayouts")) as RadTreeView;
            }
     
        }

    Note : you get this error because there is not any item(s) in your "LayoutIDRadComboBox".

    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Mario
    Mario avatar
    25 posts
    Member since:
    Jan 2012

    Posted 09 Apr 2012 Link to this post

    Thanks for the answer, Jayesh. I know that the value of items is 0. But where is my mistake in thinking? Why doesn't have an item? I have an ItemTemplate such as TreeView. This TreeView is depending from the value from the first ComboBox.How can i solve this problem?

    Best regards
    Reiner
  5. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 09 Apr 2012 Link to this post

    Hello Mario,

    please add one blank item in radcombobobx.
    <telerik:RadComboBox ID="LayoutIDRadComboBox"
                runat="server" Culture="de-DE" >
                <ItemTemplate>
                    <div id="div1">
                        <telerik:RadTreeView ID="RTVLayouts"
                            runat="server"                                                                    
                            onnodedatabound="RTVLayouts_NodeDataBound" >
                        </telerik:RadTreeView>
                    </div>
                </ItemTemplate>      
     
                                                  
                   <Items>
                         <telerik:RadComboBoxItem Text="" />
                    </Items>
                </telerik:RadComboBox>


    Thanks,
    Jayesh Goyani
  6. Sentil
    Sentil avatar
    23 posts
    Member since:
    Jul 2011

    Posted 22 Dec 2014 in reply to Jayesh Goyani Link to this post

    Hi

    I am in same position but different scenario
    I am using batch update where sample code like below , data loaded already to RadTreeView1, no issues on loading data
     <telerik:GridTemplateColumn>
    <EditItemTemplate>
     <ComboBox ID="locationSelector" Width="215"  DropDownWidth="215"
            Height="300"  runat="server" >
            <ItemTemplate>
                <div>
                    <telerik:RadTreeView ID="RadTreeView1"
                        runat="server">                   
                    </telerik:RadTreeView>
                </div>
            </ItemTemplate>
            <Items>
                <telerik:RadComboBoxItem Text="" runat="server" />
            </Items>
        </ComboBox>
     </EditItemTemplate> </telerik:GridTemplateColumn>

    when i hit save for batch update how can i fetch the selected node as i am using batch update we can change multiple items
    my batch update method
    protected void grid_BatchEditCommand(object source, GridBatchEditingEventArgs e)
            {
                foreach (GridBatchEditingCommand command in e.Commands)
                {
                    if ((command.Type == GridBatchEditingCommandType.Update))
                    {
                             //how to access selected value or node
                    }
                 }
             }

    Thanks
    Senthil
  7. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 25 Dec 2014 Link to this post

    Hi Sentil,

    Please note that Batch editing is mainly a client-side functionality and in this sense, it is a better idea to implement javascript approaches in this case. For example, there are not 10 different treeviews generated to edit each of the records as with EditForms or PopUp edit modes, but there is only 1 treeview loaded on the server which works for ideal performance and rendering optimization when opening the edit cells on the client.

    In addition, creating custom edit templates with Batch editing mode may require further handling:
    (Section Handling Advanced Templates)
    http://www.telerik.com/help/aspnet-ajax/grid-batch-editing.html

    With that being said,
    you can check the aforementioned article to see how to handle this specific scenario and access the values programmatically.

    Hope this helps.


    Regards,
    Eyup
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017