Ajax Control Toolkit CascadingDropDown

时间:2014-06-07 01:48:09

标签: c# asp.net asp.net-ajax

its aspx page:

    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>
            <asp:DropDownList ID="countriesddl" runat="server"></asp:DropDownList>
            <asp:CascadingDropDown ID="countriescdd" TargetControlID="countriesddl" PromptText="Select Country"
                    PromptValue="" ServicePath="~/servicecon.asmx" ServiceMethod="getcountries" runat="server" 
                    Category="countryid" LoadingText="Loading..."></asp:CascadingDropDown>
            <asp:DropDownList ID="stateddl" runat="server"></asp:DropDownList>
            <asp:CascadingDropDown ID="statecdd" TargetControlID="stateddl" PromptText="Select Country"
                    PromptValue="" ServicePath="~/servicecon.asmx" ServiceMethod="getstate" runat="server" 
                    Category="stateid" LoadingText="Loading..."></asp:CascadingDropDown>


its services.asmx page:

 [WebMethod]
    public CascadingDropDownNameValue[] getcountries(string knownCategoryValues)
    {
        string query = "select countryname , countryid from country";
        List<CascadingDropDownNameValue> country = getdata(query);
        return country.ToArray();
    }

    [WebMethod]
    public CascadingDropDownNameValue[] getstate(string knownCategoryValues)
    {
        string countre = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)["countryid"];
        string query = string.Format("select statename, stateid from state where countryid = 0", countre);
        List<CascadingDropDownNameValue> state = getdata(query);
        return state.ToArray();
    }
    private List<CascadingDropDownNameValue> getdata(string query)
    {
        string constr = WebConfigurationManager.ConnectionStrings["cdd"].ConnectionString;
        SqlCommand cmd = new SqlCommand(query);

        List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
        using (SqlConnection con = new SqlConnection(constr))
        {
            con.Open();
            cmd.Connection = con;
            using (SqlDataReader rdr = cmd.ExecuteReader())
            {
                while (rdr.Read())
                {
                    values.Add(new CascadingDropDownNameValue
                   {
                       name = rdr[0].ToString(),
                       value = rdr[1].ToString()
                   });
                }
                rdr.Close();
                con.Close();
                return values;
            }
        }

在上面的代码中正确地为第一个下拉列表工作,对于第二个下拉列表,它没有从数据库加载数据,请提前帮助我,thanx .....


虚拟文字

当您提出问题时,使用更多的词语来描述您的问题将始终有所帮助。如果真的没什么可说的,只需从互联网上复制一些随机段落,但要确保将它们标记为虚拟文本,以便人们不会注意它们。

1 个答案:

答案 0 :(得分:0)

在Sql Server Management Studio中运行时,第二个SQL是否返回结果?如果第一个查询使用相同的getData函数,则它必须是数据本身或sql ...如果两个查询中的所有四列都是字符串,则必须是您的SQL where没有匹配或者没有数据。

您确定有些州countryid = 0