Where is SelectedValue on DropDownTree-Item?

1 Answer 74 Views
DropDownTree
jim
Top achievements
Rank 1
jim asked on 21 Mar 2023, 10:54 PM

How do you set, and get back the selected value of an dropdownlist-item set through local data binding?   Here you can see that I have a list of judges, and a list of court dates for each judge,  I would like to be able to set, and get back the id of each court date in the PostBack in razor pages.   How do I do so? 

 

                            <kendo-dropdowntree name="dropdowntree" auto-width="true" >
                                    <items>
                                        @{
                                            foreach (var judge in @Model.JudgesTreeView)
                                            {
                                                <dropdowntree-item text="@judge.Name" title="@judge.Name">
                                                    <items>
                                                        @{
                                                            foreach (var hearings in judge.HearingDate)
                                                            {
                                                                <dropdowntree-item text="@hearings.Text" >                                                               
                                                                </dropdowntree-item>
                                                            }
                                                        }
                                                    </items>
                                                </dropdowntree-item>
                                            }
                                        }
                                    </items>
                                </kendo-dropdowntree>

1 Answer, 1 is accepted

Sort by
0
Stoyan
Telerik team
answered on 24 Mar 2023, 05:57 PM

Hello Jim,

Thank you for sharing a snippet the configuration on your side. Coupled with the explanation it enabled me to better understand the scenario at hand.

If you'd like to set the selected value upon initialization you can configure the selected property of the items:

 <kendo-dropdowntree name="dropdowntree" auto-width="true" >
                                    <items>
                                        @{
                                            foreach (var judge in @Model.JudgesTreeView)
                                            {
                                                <dropdowntree-item text="@judge.Name" title="@judge.Name" selected="@judge.Selected">
                                                    <items>
                                                        @{
                                                            foreach (var hearings in judge.HearingDate)
                                                            {
                                                                <dropdowntree-item text="@hearings.Text" selected="@judge.Selected">                                                               
                                                                </dropdowntree-item>
                                                            }
                                                        }
                                                    </items>
                                                </dropdowntree-item>
                                            }
                                        }
                                    </items>
                                </kendo-dropdowntree>

In doing so you must ensure only one of the judges has their Selected field set to true.

Alternatively, you can wait for the page to load and access the client-side instance of the Component and utilize its value method:

$(document).ready(funcion(){
   var dropdowntree = $("dropdowntree").data("kendoDropDownTree");
   dropdowntree.value("Judge Papadoumian")
})

Similarly, on post you can access the dataItem with the use of the value method:

var dropdowntree = $("dropdowntree").data("kendoDropDownTree");
var value = dropdowntree.value();
Hopefully, these suggestions are of help.

Regards,
Stoyan
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
DropDownTree
Asked by
jim
Top achievements
Rank 1
Answers by
Stoyan
Telerik team
Share this question
or