简体   繁体   English

Ajax控制工具箱CascadingDropDown

[英]Ajax Control Toolkit CascadingDropDown

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;
            }
        }

in the above code works correctly for the first dropdownlist, for the second dropdownlist its not loading the data from the databse, ple help me, thanx in advance..... 在上面的代码中,对于第一个下拉列表来说是正确的,对于第二个下拉列表来说,它没有从数据库加载数据,请帮助我,谢谢。


dummy text 虚拟文字

When you asking questions, using some more words to describe your problem will always help. 当您提出问题时,使用更多的词语来描述您的问题将总是有帮助的。 If there are really nothing more to say, just copy some random paragraph from internet, but make sure you mark them as dummy text so that people won't pay attention on them. 如果真的无话可说,只需从互联网上复制一些随机段落,但请确保将其标记为虚拟文本,以免引起人们的注意。

Does the second SQL return results when ran in Sql Server Management Studio? 在Sql Server Management Studio中运行时,第二条SQL是否返回结果? If the first query works with the same getData function it must be the data itself or the sql... If all four columns in both queries are strings, must be your SQL where is matching on nothing or there is no data. 如果第一个查询使用相同的getData函数,则它必须是数据本身或sql ...如果两个查询中的所有四列都是字符串,则必须是SQL where什么都不匹配或没有数据。

You are sure there are states where countryid = 0 ? 您确定存在countryid = 0州吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM