本文介绍了在onkeyup和onkeydown依赖于负载的dropwdonlist上进行级联dropdownlist项目更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在我的情况下,将层叠下拉列表用于Country,State,City和MainRoad.
它在选择时效果很好,但是我希望当国家项目更改onkeyup或onkeydown时,时间负载取决于州,城市或MainRoad的州项目.如何做到这一点,请提供完整的解决方案帮助.

我的代码是

Hi,

In My case using cascade dropdownlist for Country,State,City and MainRoad.
It works fine on selection but i want to that when country items change onkeyup or onkeydown that time load depended state items same for state,city or MainRoad. How can do this please provide help full solutions.

My code is

<cc1:ToolkitScriptManager ID="ToolkitScriptManager1"  runat="server">
    </cc1:ToolkitScriptManager>
   <div>
        <table cellpadding="3" cellspacing="3">
            <tr>
                <td>Country</td>
                <td>
                    <asp:DropDownList ID="dr_country" runat="server" >
                    </asp:DropDownList>
                   
                    <cc1:CascadingDropDown ID="cas_country"  runat="server"

                     Category="Country" 

                TargetControlID="dr_country" UseContextKey="true" LoadingText="Loading ......"

                PromptText="Select Country" PromptValue="" ServiceMethod="BindCountrydropdown" 

                ServicePath="CascadeDropDownService.asmx">
                    </cc1:CascadingDropDown>
                </td>
            </tr>
            <tr>
            <td>State</td>
                <td>
                <asp:DropDownList ID="dr_state" runat="server">
                    </asp:DropDownList>
                    <cc1:CascadingDropDown ID="cas_state"  runat="server"

                    Category="State" 

                TargetControlID="dr_State" ParentControlID="dr_country" LoadingText="Loading ......" 

                PromptText="Select State" PromptValue="" ServiceMethod="BindStatedropdown" 

                ServicePath="CascadeDropDownService.asmx">
                    </cc1:CascadingDropDown>
                </td>
            </tr>
            <tr>
            <td>City</td>
                <td>
                <asp:DropDownList ID="dr_city" runat="server" >
                    </asp:DropDownList>
                    <cc1:CascadingDropDown ID="cas_city"  runat="server"

                        Category="Region" TargetControlID="dr_city" ParentControlID="dr_State" PromptValue=""

                        LoadingText="Loading Cities..." PromptText="Select City" 

                        ServiceMethod="BindCitydropdown" ServicePath="CascadeDropDownService.asmx">
                    </cc1:CascadingDropDown>
                </td>
            </tr>
            <tr>
            <td>MainRoad</td>
                <td>
                <asp:DropDownList ID="dr_mainroad" runat="server">
                    </asp:DropDownList>
                    <cc1:CascadingDropDown ID="cas_mainroad"  runat="server"

                        Category="Mainroad" TargetControlID="dr_MainRoad" ParentControlID="dr_city" PromptValue=""

                        LoadingText="Loading Main Road..." PromptText="Select Mainroad"

                        ServiceMethod="BindMainroadropdown" ServicePath="CascadeDropDownService.asmx">
                    </cc1:CascadingDropDown>
                </td>
            </tr>
        </table>
   </div>




CascadeDropDownService.asmx




CascadeDropDownService.asmx

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using AjaxControlToolkit;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Collections.Specialized;

namespace PMSCloud.CascadeDropDown
{
    /// <summary>
    /// Summary description for CascadeDropDownService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.Web.Script.Services.ScriptService()]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]

    public class CascadeDropDownService : System.Web.Services.WebService
    {
        #region CommonIdTitle for Country,State,City,MainRoad
        
        [WebMethod]
        public CascadingDropDownNameValue[] BindCountrydropdown(string knownCategoryValues, string category, string contextKey)
        {
            int SubscriberId = 0;
            if (contextKey != "")
            { SubscriberId = Convert.ToInt32(contextKey); }
            SqlConnection concountry = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString);
            concountry.Open();
            SqlCommand cmdcountry = new SqlCommand("SP_Get_Mst_Country_Id_Title", concountry);
            cmdcountry.CommandType = CommandType.StoredProcedure;
            cmdcountry.Parameters.AddWithValue("@SubscriberId", SubscriberId);
            SqlDataAdapter dacountry = new SqlDataAdapter(cmdcountry);
            cmdcountry.ExecuteNonQuery();
            DataSet dscountry = new DataSet();
            dacountry.Fill(dscountry);
            concountry.Close();
            List<CascadingDropDownNameValue> countrydetails = new List<CascadingDropDownNameValue>();
            foreach (DataRow dtrow in dscountry.Tables[0].Rows)
            {
                string CountryID = dtrow["Id"].ToString();
                string CountryName = dtrow["Title"].ToString();
                countrydetails.Add(new CascadingDropDownNameValue(CountryName, CountryID));
            }
            return countrydetails.ToArray();
        }
        [WebMethod]
        public CascadingDropDownNameValue[] BindStatedropdown(string knownCategoryValues, string category)
        {
            int CountryID;
            StringDictionary countrydetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
            CountryID = Convert.ToInt32(countrydetails["Country"]);
            SqlConnection constate = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString);
            constate.Open();
            SqlCommand cmdstate = new SqlCommand("SP_Get_Mst_State_Id_Title", constate);
            cmdstate.CommandType = CommandType.StoredProcedure;
            cmdstate.Parameters.AddWithValue("Country_Id", CountryID);
            cmdstate.ExecuteNonQuery();
            SqlDataAdapter dastate = new SqlDataAdapter(cmdstate);
            DataSet dsstate = new DataSet();
            dastate.Fill(dsstate);
            constate.Close();
            List<CascadingDropDownNameValue> statedetails = new List<CascadingDropDownNameValue>();
            foreach (DataRow dtstaterow in dsstate.Tables[0].Rows)
            {
                string stateID = dtstaterow["Id"].ToString();
                string statename = dtstaterow["Title"].ToString();
                statedetails.Add(new CascadingDropDownNameValue(statename, stateID));
            }
            return statedetails.ToArray();
        }
        [WebMethod]
        public CascadingDropDownNameValue[] BindCitydropdown(string knownCategoryValues, string category)
        {
            int stateID;
            StringDictionary statedetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
            stateID = Convert.ToInt32(statedetails["State"]);
            SqlConnection conregion = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString);
            conregion.Open();
            SqlCommand cmdregion = new SqlCommand("SP_Get_Mst_City_Id_Title", conregion);
            cmdregion.CommandType = CommandType.StoredProcedure;
            cmdregion.Parameters.AddWithValue("State_Id", stateID);
            cmdregion.ExecuteNonQuery();
            SqlDataAdapter daregion = new SqlDataAdapter(cmdregion);
            DataSet dsregion = new DataSet();
            daregion.Fill(dsregion);
            conregion.Close();
            List<CascadingDropDownNameValue> regiondetails = new List<CascadingDropDownNameValue>();
            foreach (DataRow dtregionrow in dsregion.Tables[0].Rows)
            {
                string regionID = dtregionrow["Id"].ToString();
                string regionname = dtregionrow["Title"].ToString();
                regiondetails.Add(new CascadingDropDownNameValue(regionname, regionID));

            }
            return regiondetails.ToArray();
        }
        [WebMethod]
        public CascadingDropDownNameValue[] BindMainroadropdown(string knownCategoryValues, string category)
        {
            int City;
            StringDictionary citydetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
            City = Convert.ToInt32(citydetails["Region"]);
            SqlConnection conmainroad = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString);
            conmainroad.Open();
            SqlCommand cmdmainroad = new SqlCommand("SP_Get_Mst_MainRoad_Id_Title", conmainroad);
            cmdmainroad.CommandType = CommandType.StoredProcedure;
            cmdmainroad.Parameters.AddWithValue("City_Id", City);
            cmdmainroad.ExecuteNonQuery();
            SqlDataAdapter dacity = new SqlDataAdapter(cmdmainroad);
            DataSet dsmainroad = new DataSet();
            dacity.Fill(dsmainroad);
            conmainroad.Close();
            List<CascadingDropDownNameValue> mainroaddetails = new List<CascadingDropDownNameValue>();
            foreach (DataRow dtmainroadrow in dsmainroad.Tables[0].Rows)
            {
                string mainroadID = dtmainroadrow["Id"].ToString();
                string mainraodname = dtmainroadrow["Title"].ToString();
                mainroaddetails.Add(new CascadingDropDownNameValue(mainraodname, mainroadID));

            }
            return mainroaddetails.ToArray();
        }
        #endregion
}
}

推荐答案


这篇关于在onkeyup和onkeydown依赖于负载的dropwdonlist上进行级联dropdownlist项目更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 13:37