locked
Cascading Drop Downs - Pre-Select items (contextkey) RRS feed

  • Question

  • User756585424 posted

    Hi everyone,

     

    I have a problem with 3 cascading drop downs.  They are on a content page, so I have a Master Page as well.  They work just fine but once the user saves the data and then comes back to the same page, I would like to show them what was previously saved.  How can I pre-select items in the drop downs that I get from my SQL server db?  I tried jquery, javascript, vb code behind and no luck so far.  I'm sure i'm doing something wrong.  Here is my code:

    I've been trying to send my webservice a contextkey for the first drop down.  When I debug the webservice, and I manually enter a context key, i get the correct values back with the value that equals my context key having <isDefaultValue>True</isDefaultValue>. 

    Aspx page:

    <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional"><ContentTemplate>
        
                    <cc1:CascadingDropDown ID="drpdwnProcedures_CascadingDropDown" runat="server" 
                    Category="CategoryName" Enabled="True" LoadingText="[Loading Procedures...]" 
                    PromptText="Select a Category" ServiceMethod="GetProcedures" 
                    ServicePath="Procedures.asmx" TargetControlID="drpdwnProcedures"   BehaviorID="myFirstDropDown"  
                    UseContextKey="True">
                </cc1:CascadingDropDown>
                <asp:DropDownList ID="drpdwnProcedures" runat="server" 
                    Width="200px" AutoPostBack="True">
                </asp:DropDownList>
         
    
                <asp:DropDownList ID="drpdwnCatheter" runat="server" 
                    Width="200px">
                </asp:DropDownList>
                <cc1:CascadingDropDown ID="drpdwnCatheter_CascadingDropDown" runat="server" 
                    Enabled="True" 
                    TargetControlID="drpdwnCatheter" 
                    ParentControlID="drpdwnProcedures"
                     ServiceMethod="GetCatheters" 
                     Category="Catheters"
                    PromptText="Select a Catheter"
                    LoadingText="[Loading Catheters...]"
                    ServicePath="Procedures.asmx">
                </cc1:CascadingDropDown>
              
    
              <asp:DropDownList ID="drpdwnLocation" runat="server" 
                  Width="200px">
              </asp:DropDownList>
              <cc1:CascadingDropDown ID="drpdwnLocation_CascadingDropDown" runat="server" 
                  Enabled="True"      
                  TargetControlID="drpdwnLocation" 
                    ParentControlID="drpdwnCatheter"
                     ServiceMethod="GetLocations" 
                     Category="Locations"
                    PromptText="Select a Location"
                    LoadingText="[Loading Locations...]"
                    ServicePath="Procedures.asmx">
              </cc1:CascadingDropDown>
          
    
                             
      </ContentTemplate>
        </asp:UpdatePanel>

     

    WebService (part of it that gets data for my first drop down):


    Imports System.Web
    Imports System.Web.Services
    Imports System.Web.Services.Protocols
    Imports AjaxControlToolkit
    Imports System.Data
    Imports System.Data.SqlClient
    Imports System.Linq
    ' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
    ' <System.Web.Script.Services.ScriptService()> _
    <WebService(Namespace:="http://tempuri.org/")> _
    <System.Web.Script.Services.ScriptService()> _
    <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    Public Class Procedures
        Inherits System.Web.Services.WebService
        Dim db As New PACUNewDataContext
    
        <WebMethod()> _
        Public Function GetProcedures(ByVal knownCategoryValues As String, _
                                   ByVal category As String, ByVal contextKey As String) As CascadingDropDownNameValue()
            Dim SampleSource As New List(Of CascadingDropDownNameValue)
            Try
    
                Dim Categories = From x In db.ProcedureNames Select New With {x.Type, x.ID}
                Dim CategoryName As String
                Dim CategoryValue As String
                For Each c In Categories
                    CategoryName = c.Type
                    CategoryValue = c.ID
    
    
                    If Not String.IsNullOrEmpty(contextKey) AndAlso contextKey = CategoryValue Then
                        SampleSource.Add(New CascadingDropDownNameValue( _
                                                         CategoryName, CategoryValue, True))
                    Else
                        SampleSource.Add(New CascadingDropDownNameValue( _
                                                         CategoryName, CategoryValue))
    
                    End If
    
                   
    
                Next
    
    
    
                Return SampleSource.ToArray()
    
            Catch ex As Exception
                Throw ex
            End Try
        End Function

    Code behind page (vb)
     
     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
    drpdwnCatheter_CascadingDropDown.ContextKey = 4 'just a random value for testing, tried to set the contextkey here also
    
    
      End Sub

    Javascript (tried to set the context key here)
    <script type="text/javascript" language="javascript">
    	    function pageLoad() {
    
    	        $find("myFirstDropDown").set_contextKey("4");  //set the contextKey
    	       
    	    }
            </script> 
     
    Any help would be appreciated.  Thanks. 


     

     

    Wednesday, July 14, 2010 8:13 AM

Answers

  • User756585424 posted

    I figured it out after about a day of researching this.  I used this post (http://www.ajaxlines.com/ajax/stuff/article/ajaxnet_multiple_cascade_drop_down_list_pre_load_values_from_db.php)

    I had to do the following:

    1. The first drop down, actually it's the drop down extender, and not the drop down itself (you have to Imports AjaxControlToolkit) needs to be set by using its .selectedvalue property. 

    2. The rest of the drop down extenders take their value by using the .contextkey property. 


     If Not Page.IsPostBack Then
    
      'First Drop Down List
      drpdwnProcedures_CascadingDropDown.SelectedValue = HiddenProcedures.Value 'Any value that you want.  
    
      'Second Drop Down List
      drpdwnCatheter_CascadingDropDown.ContextKey = GetCatheterID 'the ID that's returned from my DB
    
         'Third Drop Down List
     drpdwnLocation_CascadingDropDown.ContextKey = LocID 'the ID that's returned from my DB
    
    End Sub



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 14, 2010 12:00 PM