RadCombobox in RadTreeList

2 posts, 0 answers
  1. babymonsta
    babymonsta avatar
    4 posts
    Member since:
    Mar 2011

    Posted 28 Mar 2012 Link to this post

    Hi all,

    Im using the latest telerik rad ajax controls (ASP.NET AJAX Q1 2012 version 12.1.215.0). I have a treelist which has a template column whereby I placed a combobox in it. What my page does is I allow the user to select options in the combobox and when they click the save button, my function will create 1 record per row which has a selected option in the comboboxes. Here is my code

    <telerik:RadAjaxLoadingPanel ID="RadTreeAjax" runat="server" Skin="Windows7" EnableSkinTransparency="False" Transparency="30" />
        <telerik:RadTreeList ID="RadTreeList1" runat="server" AllowPaging="true" PageSize="15" Skin="Windows7" OnNeedDataSource="RadTreeList1_OnNeedDataSource" OnItemDataBound="RadTreeList1_OnItemDataBound"
            AutoGenerateColumns="false" AllowSorting="true" DataKeyNames="ParentId" ParentDataKeyNames="GoalId" Width="1070px" GridLines="None" >
            <Columns>
                <telerik:TreeListBoundColumn DataField="Id" UniqueName="Id" HeaderText="Id" Visible="false" />
                <telerik:TreeListBoundColumn DataField="ParentId" UniqueName="ParentId" HeaderText="ParentId" Visible="false" />
                <telerik:TreeListBoundColumn DataField="GoalId" UniqueName="GoalId" HeaderText="GoalId" Visible="false" />
                <telerik:TreeListBoundColumn DataField="InterventionId" UniqueName="InterventionId" HeaderText="InterventionId" Visible="false" />
                <telerik:TreeListBoundColumn DataField="Goal" UniqueName="Goal" HeaderText="Goal" ItemStyle-Width="320px" HeaderStyle-Width="320px" />
                <telerik:TreeListBoundColumn DataField="Intervention" UniqueName="Intervention" HeaderText="Intervention" ItemStyle-Width="495px" HeaderStyle-Width="495px" />
                <telerik:TreeListTemplateColumn UniqueName="GoalStatus" HeaderText="Status" ItemStyle-Width="100px" HeaderStyle-Width="100px" >
                    <ItemTemplate>
                        <telerik:RadComboBox ID="ddlGoalStatus" Width="90px" Filter="StartsWith" AllowCustomText="true" EmptyMessage="" AutoPostBack="true" EnableViewState="true" runat="server" Skin="Windows7" CssClass="tabbar_tasklist_last" RegisterWithScriptManager="False">
                        </telerik:RadComboBox>
                    </ItemTemplate>
                </telerik:TreeListTemplateColumn>
                <telerik:TreeListTemplateColumn UniqueName="InterventionStatus" ItemStyle-Width="105px" HeaderStyle-Width="105px" >
                    <ItemTemplate>
                        <telerik:RadComboBox ID="ddlInterventionStatus" Width="95px" Filter="StartsWith" AllowCustomText="true" EmptyMessage="" AutoPostBack="true" runat="server" Skin="Windows7" CssClass="tabbar_tasklist_last" RegisterWithScriptManager="False">
                        </telerik:RadComboBox>
                    </ItemTemplate>
                </telerik:TreeListTemplateColumn>
            </Columns>
        </telerik:RadTreeList>

    protected void RadTreeList1_OnNeedDataSource(object sender, TreeListNeedDataSourceEventArgs e)
            {
                RadTreeList1.DataSource = GetGoalsAndInterventions();
            }
     
            protected void RadTreeList1_OnItemDataBound(object sender, Telerik.Web.UI.TreeListItemDataBoundEventArgs e)
            {
                if (e.Item is TreeListDataItem)
                {
                    TreeListDataItem dataItem = e.Item as TreeListDataItem;
     
                    RadComboBox ddlGoalStatus = (RadComboBox)e.Item.FindControl("ddlGoalStatus");
                    RadComboBox ddlInterventionStatus = (RadComboBox)e.Item.FindControl("ddlInterventionStatus");
     
                    ddlGoalStatus.DataSource = GetGoalStatusMaster();
                    ddlGoalStatus.DataValueField = "GoalStatusId";
                    ddlGoalStatus.DataTextField = "Value";
                    ddlGoalStatus.DataBind();
                     
     
                    ddlInterventionStatus.DataSource = GetInterventionStatusMaster();
                    ddlInterventionStatus.DataValueField = "InterventionStatusId";
                    ddlInterventionStatus.DataTextField = "Value";
                    ddlInterventionStatus.DataBind();
     
                    if (dataItem.ItemType == TreeListItemType.Item || dataItem.ItemType == TreeListItemType.AlternatingItem)
                    {
                        TableCell cell = dataItem["ParentId"];
                        string value = cell.Text;
     
                        if (value != " ")
                        {
                            ddlInterventionStatus.Visible = false;
                            ddlGoalStatus.Visible = true;
                        }
     
                        TableCell cell2 = dataItem["InterventionId"];
                        string value2 = cell2.Text;
     
                        if (value2 != " ")
                        {
                            ddlGoalStatus.Visible = false;
                            ddlInterventionStatus.Visible = true;
                        }
                    }
     
                }
            }

    private void SaveGoalStatus()
            {
                // delete all goal status from database
                DeleteInterventionStatus();
                DeleteGoalStatus();
     
                foreach (TreeListDataItem item in RadTreeList1.Items)
                {
                    string s1 = string.Empty;
                    string s2 = string.Empty;
                     
                    RadComboBox ddlInterventionStatus = (RadComboBox)item.FindControl("ddlInterventionStatus");
     
                    if (item.ItemType == TreeListItemType.Item || item.ItemType == TreeListItemType.AlternatingItem)
                    {
                        RadComboBox ddlGoalStatus = (RadComboBox)item.FindControl("ddlGoalStatus");
                        string s = ddlGoalStatus.SelectedItem.Text;
     
                        if (ddlGoalStatus.SelectedItem != null)
                        {
                            TableCell cell = item["Id"];
                            string ProblemGoalId = cell.Text;
                 
     
                             
     
                            if (ProblemGoalId != " ")
                            {
                                try
                                {
                                    CarePlan_GoalStatus oGoalStatus = new CarePlan_GoalStatus();
                                    oGoalStatus.CarePlanId = this.CarePlanID;
                                    oGoalStatus.ProblemGoalId = new Guid(ProblemGoalId);
                                    oGoalStatus.GoalStatusId = GetGoalId(s);
                                    oGoalStatus.CreatedBy = this.UserId;
                                    oGoalStatus.ModifiedBy = this.UserId;
     
                                    oGoalStatus = WCFSvcClient.CCITDataService.Insert(oGoalStatus) as CarePlan_GoalStatus;
                                }
                                catch (Exception ex)
                                {
                                    lblMessage.Text = "Create Goal Status" + ex.Message;
                                }
                            }
                        }
                    }
     
                    if (ddlInterventionStatus.SelectedItem != null)
                    {
                        if (item.ItemType == TreeListItemType.Item || item.ItemType == TreeListItemType.AlternatingItem)
                        {
                            TableCell cell = item["Id"];
                            string GoalInterventionId = cell.Text;
     
                            if (GoalInterventionId != " ")
                            {
                                try
                                {
                                    CarePlan_InterventionStatus oInterventionStatus = new CarePlan_InterventionStatus();
                                    oInterventionStatus.CarePlanId = this.CarePlanID;
                                    oInterventionStatus.GoalInterventionId = new Guid(GoalInterventionId);
                                    oInterventionStatus.InterventionStatusId = new Guid(ddlInterventionStatus.SelectedItem.Value);
                                    oInterventionStatus.CreatedBy = this.UserId;
                                    oInterventionStatus.ModifiedBy = this.UserId;
     
                                    oInterventionStatus = WCFSvcClient.CCITDataService.Insert(oInterventionStatus) as CarePlan_InterventionStatus;
                                }
                                catch (Exception ex)
                                {
                                    lblMessage.Text = "Create Intervention Status" + ex.Message;
                                }
                            }
                        }
     
                        #region Populate Info On Page
                        BindToViewState();
     
                        // call first to populate the ddlSection selection
                        DisplayCarePlanInfoOnPage();
     
                        // the values are originally populated on selected change of ddlSection but due to population of data on first load of page
                        // the page has no selected index change, this this has to be done manually
                        GetProblemBySection(ddlSection.SelectedItem.Value);
     
                        // call again to GET the selected value of ddlProblem
                        DisplayCarePlanInfoOnPage();
     
                        foreach (DataRow row in ProblemTable.Rows)
                        {
                            if (row["Value"].ToString() == ddlProblem.SelectedItem.Text)
                                txtProblemDescription.Text = row["Description"].ToString();
                        }
                        #endregion
                    }
                }
            }

    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="ddlSection">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="ddlSection" />
                        <telerik:AjaxUpdatedControl ControlID="ddlProblem" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="ddlProblem">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="ddlProblem" />
                        <telerik:AjaxUpdatedControl ControlID="txtProblemDescription" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="RadTreeList1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadTreeList1" LoadingPanelID="RadTreeAjax" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="cpTB">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="CarePlanPanel" LoadingPanelID="CarePlanAjax" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="btnSearch">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="Panel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>


    A little explanation bout my  page is onpageload if there is an existing data in the database I will populate the treelist and also bind the comboboxes in the treelist based on the value saved in the database (this works fine). But my problem now is when I select a different value and click the save button, it is supposed to create a row in my database table with the new combobox selection however it doesnt.

    As you can see, I bind my comboboxes in the itemdatabound and in my Save function what I do is I clear my database table and then I reinsert new rows into the table based on rows in the treelist which has a selected value in the combobox. As for now I am only testing based on ddlGoalStatus combobox so please ignore the ddlInterventionStatus combobox. In my save function, I have a line which says "string s = ddlGoalStatus.SelectedItem.Text;" and the value I retrieved is ALWAYS the previous value and not the newly selected value. Am I doing anything wrong? 

    Please help.

    Thanks!

  2. Antonio Stoilkov
    Admin
    Antonio Stoilkov avatar
    530 posts

    Posted 02 Apr 2012 Link to this post

    Hi Jessie,

    Based on your code and description I have assembled a sample project working properly on my side. You could take a look at it and see if there are any differences at your end. Note that the RadTreeList ViewState should be enabled in order for the scenario to work. Please check if some wrapper or the page have its ViewState disabled.

    Greetings,
    Antonio Stoilkov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top