我在我的网站上很多地方使用的网页上有三个CascadingDropDown
s。他们从数据库中加载了国家,地区和地区名称。我已经成功绑定了数据并将它们设置为级联。但是当用户在我的网站上注册时,我想在三个CascadingDropDown
之间预先选择三个值。从CascadingDropDown中的数据库预填充数据
注册之后,我还需要在管理区域看到他们的数据,我还需要预先选择三个CascadingDropDown
,并选择用户的值。但我无法弄清楚如何做到这一点。
我的web服务代码:
namespace ZetaSolutions.WebProjects.Web.Modules
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService()]
public class PlaceSelection : System.Web.Services.WebService
{
[WebMethod]
public CascadingDropDownNameValue[] BindCountryDropDown(string knownCategoryValues, string category)
{
SqlConnection conCountry = new SqlConnection(ZetaConfig.ConnectionString);
conCountry.Open();
SqlCommand cmdCountry = new SqlCommand("SELECT * FROM Country ORDER BY Name", conCountry);
SqlDataAdapter daCountry = new SqlDataAdapter(cmdCountry);
cmdCountry.ExecuteNonQuery();
DataSet dsCountry = new DataSet();
daCountry.Fill(dsCountry);
conCountry.Close();
List<CascadingDropDownNameValue> countryDetails = new List<CascadingDropDownNameValue>();
foreach (DataRow dtRow in dsCountry.Tables[0].Rows)
{
string countryId = dtRow["CountryID"].ToString();
string countryName = dtRow["Name"].ToString();
countryDetails.Add(new CascadingDropDownNameValue(countryName, countryId));
}
return countryDetails.ToArray();
}
[WebMethod]
public CascadingDropDownNameValue[] BindDistrictDropDown(string knownCategoryValues, string category)
{
int countryId;
StringDictionary countryDetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
countryId = Convert.ToInt32(countryDetails["Country"]);
SqlConnection conDistrict = new SqlConnection(ZetaConfig.ConnectionString);
conDistrict.Open();
SqlCommand cmdDistrict = new SqlCommand("SELECT * FROM District WHERE [email protected] ORDER BY Name", conDistrict);
cmdDistrict.Parameters.AddWithValue("@CountryID", countryId);
cmdDistrict.ExecuteNonQuery();
SqlDataAdapter daDistrict = new SqlDataAdapter(cmdDistrict);
DataSet dsDistrict = new DataSet();
daDistrict.Fill(dsDistrict);
conDistrict.Close();
List<CascadingDropDownNameValue> districtDetails = new List<CascadingDropDownNameValue>();
foreach (DataRow dtDistrictRow in dsDistrict.Tables[0].Rows)
{
string districtId = dtDistrictRow["DistrictID"].ToString();
string districtName = dtDistrictRow["Name"].ToString();
districtDetails.Add(new CascadingDropDownNameValue(districtName, districtId));
}
return districtDetails.ToArray();
}
[WebMethod]
public CascadingDropDownNameValue[] BindAreaDropDown(string knownCategoryValues, string category)
{
int districtId;
StringDictionary districtDetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
districtId = Convert.ToInt32(districtDetails["District"]);
SqlConnection conArea = new SqlConnection(ZetaConfig.ConnectionString);
conArea.Open();
SqlCommand cmdArea = new SqlCommand("SELECT * FROM Area WHERE [email protected] ORDER BY Name", conArea);
cmdArea.Parameters.AddWithValue("@DistrictID ", districtId);
cmdArea.ExecuteNonQuery();
SqlDataAdapter daArea = new SqlDataAdapter(cmdArea);
DataSet dsArea = new DataSet();
daArea.Fill(dsArea);
conArea.Close();
List<CascadingDropDownNameValue> areaDetails = new List<CascadingDropDownNameValue>();
foreach (DataRow dtAreaRow in dsArea.Tables[0].Rows)
{
string areaId = dtAreaRow["AreaID"].ToString();
string areaName = dtAreaRow["Name"].ToString();
areaDetails.Add(new CascadingDropDownNameValue(areaName, areaId));
}
return areaDetails.ToArray();
}
}
}
我的aspx代码:
<table>
<tr>
<td>
Country:
</td>
<td>
<asp:DropDownList ID="ddlCountry" runat="server"></asp:DropDownList>
<ajaxToolkit:CascadingDropDown ID="CountryCascading" runat="server" Category="Country" TargetControlID="ddlCountry" LoadingText="Loading Countries..." PromptText="Select Country" ServiceMethod="BindCountryDropDown" ServicePath="PlaceSelection.asmx">
</ajaxToolkit:CascadingDropDown>
</td>
</tr>
<tr>
<td>
District:
</td>
<td>
<asp:DropDownList ID="ddlDistrict" runat="server"></asp:DropDownList>
<ajaxToolkit:CascadingDropDown ID="DistrictCascading" runat="server" Category="District" TargetControlID="ddlDistrict" ParentControlID="ddlCountry" LoadingText="Loading Districts..." PromptText="Select District" ServiceMethod="BindDistrictDropDown" ServicePath="PlaceSelection.asmx">
</ajaxToolkit:CascadingDropDown>
</td>
</tr>
<tr>
<td>
Area:
</td>
<td>
<asp:DropDownList ID="ddlArea" runat="server"></asp:DropDownList>
<ajaxToolkit:CascadingDropDown ID="AreaCascading" runat="server" Category="Area" TargetControlID="ddlArea" ParentControlID="ddlDistrict" LoadingText="Loading Areas..." PromptText="select Areas" ServiceMethod="BindAreaDropDown" ServicePath="PlaceSelection.asmx">
</ajaxToolkit:CascadingDropDown>
</td>
</tr>
</table>
谁能告诉我,我怎么能解决我的问题?这很紧急。提前致谢。
ChrisBint,我尝试过这一点,但是这并不在下拉列表... – Ratul