locked
Cascading Drop Down List RRS feed

  • Question

  • Is it possible to user the AJAX cascading drop down list without using the service method?

    I'd rather just use my existing SQL query connection to get the contents for the second drop down list, but i have been unable to find a good example of this.

    Thanks!
    Thursday, January 8, 2009 4:50 PM

Answers

  • Hello,


    Do you want to bind data to the second DropdownList control according to the first one's choice?


    To achieve this without using Ajax CascadingDropdownList control toolkit and service, you could try this:

    Set the first control’s Autopostback attribute to be true and the second control’s Enabled attribute to be false, and manually change it in the code behind, some code snip of the first control’s SelectedIndexChanged event might be like:

        protected void layer1_SelectedIndexChanged(object sender, EventArgs e)  
        {  
              
            string pstr = layer1.SelectedValue;  
            int pid = 0;  
            if(int.TryParse(pstr, out pid) && pid != 0)  
            {  
                if (layer2.Enabled == false)  
                {  
                    layer2.Enabled = true;  
                }  
                string sql = "select sid, sname from community where pid=" + pid;  
                //fetch data from database  
                //DAL_DTProvider is the class to do this  
                layer2.DataSource = DAL_DTProvider.GetData(sql);  
                layer2.DataTextField = "sname";  
                layer2.DataValueField = "sid";  
                layer2.DataBind();  
            }  
        } 
    But, one of the drawbacks is the whole page needs to be freshen after we postback data, if you use Ajax and service, that drawback is not existed.

    Besides, for more resolutions or suggestions, please refer to our ASP.NET forum here or ASP.NET AJAX Control Toolkit forum here, there are more experts there.

    If I unfortunately misunderstand you, please let me know.

    Hoping that could help you!
    Best regards,

    Roahn
    • Marked as answer by liurong luo Thursday, January 15, 2009 1:40 AM
    Tuesday, January 13, 2009 7:35 AM