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;
}
}
虚拟文字
当您提出问题时,使用更多的词语来描述您的问题将始终有所帮助。如果真的没什么可说的,只需从互联网上复制一些随机段落,但要确保将它们标记为虚拟文本,以便人们不会注意它们。答案 0 :(得分:0)
在Sql Server Management Studio中运行时,第二个SQL是否返回结果?如果第一个查询使用相同的getData
函数,则它必须是数据本身或sql ...如果两个查询中的所有四列都是字符串,则必须是您的SQL where
没有匹配或者没有数据。
您确定有些州countryid = 0
?