0

我有两个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();
}
4

1 回答 1

0

我自己找到了解决方案。一个简单但有效的解决方案。只需0.1秒后将ddl的index改为0即可,只要ajax请求快于0.1秒即可!

$(function () {
        $("#MainContent_Location_State").change(function () {
            setTimeout(function () { document.getElementById('MainContent_Location_County').selectedIndex = 0; }, 100);
        });
});
于 2013-04-25T18:19:21.940 回答