我有两个ajax:CascadingDropDown,一个是州,一个是县。就像用户更改状态一样,该县将重新填充新数据。但是,问题是,一旦县有新数据,选择的指标还是一样的。当用户更改状态时,如何将选定的索引设置为 0 ?谢谢!
<asp:DropDownList ID="Location_State" runat="server">
</asp:DropDownList>
<ajax:CascadingDropDown ID="StateCascading" runat="server" Category="State"
TargetControlID="Location_State"
ServiceMethod="BindStateDropdown"
ServicePath="CountyService.asmx">
</ajax:CascadingDropDown>
<asp:DropDownList ID="Location_County" runat="server">
</asp:DropDownList>
<ajax:CascadingDropDown ID="CountyCascading" runat="server" Category="County"
TargetControlID="Location_County"
ParentControlID="Location_State"
ServiceMethod="BindCountyDropdown"
ServicePath="CountyService.asmx">
</ajax:CascadingDropDown>
这是填充县列表的功能
[WebMethod]
public CascadingDropDownNameValue[] BindCountyDropdown(string knownCategoryValues, string category)
{
StringDictionary statedetails = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
List<CascadingDropDownNameValue> countydetails = new List<CascadingDropDownNameValue>();
string tableName = "county";
string sqlSQL = "";
string sqlConnStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
SqlConnection sqlConn = new SqlConnection(sqlConnStr);
sqlConn.Open();
sqlSQL = "SELECT [NAME], [CNTY_FIPS] FROM " + tableName + " [county] WHERE (\[STATE_FIPS] = @STATE_FIPS order by name";
SqlCommand cmdSql = new SqlCommand(sqlSQL, sqlConn);
((SqlParameter)cmdSql.Parameters.Add("@STATE_FIPS", SqlDbType.VarChar)).Value = statedetails["State"];
SqlDataReader rdr = cmdSql.ExecuteReader();
while (rdr.Read())
{
countydetails.Add(new CascadingDropDownNameValue(rdr["NAME"].ToString(), rdr["CNTY_FIPS"].ToString()));
}
rdr.Close();
sqlConn.Close();
return countydetails.ToArray();
}