Answered by:
How to Double cascade my dropdownlist (AJAX ControlToolkit - Cascading DropdownList)

Question
-
User-680159048 posted
Hey there,
I hope this is the right forum for it, I am in the process of updating an existing VB.Net web application.
My user control uses the AJAX ControlToolkit to pre populate the next dropdownlist based on the previous item selected in another dropdown.
I was hoping someone could enlighten me on how to cascade all the way down the dropdownlist chain. (some projects only have one phase and one task)
EXAMPLE: ddlProject -> ddlProjectPhase -> ddlProjectPhaseTask
So if I select a Project and it only has 1 phase, then cascade to task and if it only has one task then select that task.
Currently i have to Select my project (which populates 1 phase), then i have to select that phase (which populates 1 task), then i have to select that 1 task...
I want it to be smart enough to only make manual selections if there are more the 1 value to choose from, other wise just pre-populate all dropdowns with that 1 lonesome value in the list.
My Phase Code:
<WebMethod()> _ Public Function GetParentAccountProjectTasks(ByVal knownCategoryValues As String, ByVal category As String) As AjaxControlToolkit.CascadingDropDownNameValue() Dim Value As String = Replace(Replace(knownCategoryValues, ";", ""), "undefined:", "") Dim CategoryValue() As String = Split(category, ",") 'this get the project id Value = Value.Substring(Value.IndexOf(".") + 1) Dim objRow As TimeLiveDataSet.AccountProjectTaskRow Dim objAccountProjectTaskBLL As New AccountProjectTaskBLL Dim objTable As TimeLiveDataSet.AccountProjectTaskDataTable objTable = objAccountProjectTaskBLL.GetParentAccountProjectTasksByAccountProjectId(Value, CategoryValue(0)) Dim values As New Generic.List(Of AjaxControlToolkit.CascadingDropDownNameValue) For Each objRow In objTable.Rows values.Add(New AjaxControlToolkit.CascadingDropDownNameValue(objRow.TaskName, objRow.AccountProjectTaskId)) Next Me.Context.Response.Cache.SetCacheability(HttpCacheability.ServerAndNoCache) Return values.ToArray End Function
My Task Code:
<WebMethod()> _ Public Function GetParentAccountProjectTasks(ByVal knownCategoryValues As String, ByVal category As String) As AjaxControlToolkit.CascadingDropDownNameValue() Dim Value As String = Replace(Replace(knownCategoryValues, ";", ""), "undefined:", "") Dim CategoryValue() As String = Split(category, ",") 'this get the project id Value = Value.Substring(Value.IndexOf(".") + 1) Dim objRow As TimeLiveDataSet.AccountProjectTaskRow Dim objAccountProjectTaskBLL As New AccountProjectTaskBLL Dim objTable As TimeLiveDataSet.AccountProjectTaskDataTable objTable = objAccountProjectTaskBLL.GetParentAccountProjectTasksByAccountProjectId(Value, CategoryValue(0)) Dim values As New Generic.List(Of AjaxControlToolkit.CascadingDropDownNameValue) For Each objRow In objTable.Rows values.Add(New AjaxControlToolkit.CascadingDropDownNameValue(objRow.TaskName, objRow.AccountProjectTaskId)) Next Me.Context.Response.Cache.SetCacheability(HttpCacheability.ServerAndNoCache) Return values.ToArray End Function
Any help would be greatly appreciated !!
Thanks. sc
Sunday, March 12, 2017 3:40 PM
Answers
-
User-271186128 posted
Hi clarksss,
Please try to set defaultValue property to true when you add item to list if there is only one item.
For example:
If objTable.Rows.Count == 1 Then values.Add(New AjaxControlToolkit.CascadingDropDownNameValue(objRow.TaskName, objRow.AccountProjectTaskId, True)) Else For Each objRow In objTable.Rows values.Add(New AjaxControlToolkit.CascadingDropDownNameValue(objRow.TaskName, objRow.AccountProjectTaskId)) Next End If
Best Regards,
Dillion- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, March 13, 2017 11:04 AM
All replies
-
User-271186128 posted
Hi clarksss,
Please try to set defaultValue property to true when you add item to list if there is only one item.
For example:
If objTable.Rows.Count == 1 Then values.Add(New AjaxControlToolkit.CascadingDropDownNameValue(objRow.TaskName, objRow.AccountProjectTaskId, True)) Else For Each objRow In objTable.Rows values.Add(New AjaxControlToolkit.CascadingDropDownNameValue(objRow.TaskName, objRow.AccountProjectTaskId)) Next End If
Best Regards,
Dillion- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, March 13, 2017 11:04 AM -
User-680159048 posted
Thanks, I knew it was something simple.. thanks for pointing that out and sharing your knowledge !
Monday, March 13, 2017 4:50 PM