CascadingDropDown 联动
CascadingDropDown控件用于级连下拉列表的选择,当没有选择第一级下接列表时,第二级是不可选的(从服务器获得数据然后再显示数据)。
属性列表:
TargetControlID:对应的下拉框表控件的ID
Category:当前下拉列表的类型
PromptText:当下拉列表中无数据或没有选择数据时给用户的提示
LoadingText:加载下拉列表数据时的提示
ServicePath:下拉列表获取数据所要的WEB服务路径
ServiceMethod:WEB服务方法
ParentControlID:控制此下拉列表控件的父级控件
SelectedValue:默认的选择值
常见问题和使用技巧
常见问题:在中了联动下拉列表组之后,页面的回送会引发服务器端掷出“Invalid postback or callback argument”的异常,服务器端也无法取得每个下拉框表中的条目?
使用技巧:我们可以在web.config中加入<pages enableEventValidation="true" />或者在当前页面注册<%@ Page Language="C#" EnableEventValidation="false" %>这样会导至应该程序的安全性。
-------------------------------------------------------
注意CascadingDropDownr控件中的Category设置,Category主要就是为你CascadingDropDownr控件对应的下拉列表控件选定的值取个名字,好区分是下拉列表的值,所以这个得取的不一样。ServiceMethod主要就是对应WebSerivce的方法了,指明当前CascadingDropDown控件使用哪个WebSerivce中的方法,其它的么就不细说了。
-------------------------------------------------------------
一。实现两级联动
前台脚本:
---------------------------<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Label ID="Label1" runat="server" Text="学院"></asp:Label>
<asp:DropDownList ID="ddlstXy" runat="server" Height="16px" Width="109px">
</asp:DropDownList>
<cc1:CascadingDropDown ID="CasdropdownXy" runat="server"
TargetControlID =ddlstXy
LoadingText="加载中。。。"
ServiceMethod="BindCollegeDropDownList"
ServicePath ="~/WebService/AutoCompleteService.asmx"
PromptText="--请选择--"
Category=jxdw >
</cc1:CascadingDropDown>
<asp:Label ID="Label2" runat="server" Text="专业"></asp:Label>
<asp:DropDownList ID="ddlstZy" runat="server" Height="17px" Width="113px" AutoPostBack="True" >
</asp:DropDownList>
<cc1:CascadingDropDown ID="CasdropdownZy" runat="server"
ParentControlID="ddlstXy"
TargetControlID="ddlstZy"
PromptText="--请选择--"
ServiceMethod="BindProfessionalDropDownList"
ServicePath="~/WebService/AutoCompleteService.asmx"
Category =zy>
</cc1:CascadingDropDown>
</div>
------------------------
后台:
WEB服务文件AutoCompleteService.cs
public CascadingDropDownNameValue[] BindCollegeDropDownList(string knownCategoryValues, string category)
{
List<CascadingDropDownNameValue> categorylist = new List<CascadingDropDownNameValue>();
DataTable dt = departmentBll.GetCollegeDownlist();
for (int i = 0; i < dt.Rows.Count; i++)
{
categorylist.Add(new CascadingDropDownNameValue(dt.Rows["dwmc"].ToString(), dt.Rows["dwbh"].ToString()));
}
return categorylist.ToArray();
}
public AjaxControlToolkit.CascadingDropDownNameValue[] BindProfessionalDropDownList string knownCategoryValues, string category)
{
StringDictionary categoryList = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
List<CascadingDropDownNameValue> zylist = new List<CascadingDropDownNameValue>();
ProfessionalBLL professionalBll = new ProfessionalBLL();
string strWhere = "jw_ssdwbh='" + categoryList["jxdw"] + "'";
DataTable dt = professionalBll.GetProfessionalByWhere(strWhere);
for (int i = 0; i < dt.Rows.Count; i++)
{
zylist.Add(new AjaxControlToolkit.CascadingDropDownNameValue(dt.Rows["zymc"].ToString(), dt.Rows["zybh"].ToString()));
}
return zylist.ToArray();
}--------------------------------------------------------------
属性列表:
TargetControlID:对应的下拉框表控件的ID
Category:当前下拉列表的类型
PromptText:当下拉列表中无数据或没有选择数据时给用户的提示
LoadingText:加载下拉列表数据时的提示
ServicePath:下拉列表获取数据所要的WEB服务路径
ServiceMethod:WEB服务方法
ParentControlID:控制此下拉列表控件的父级控件
SelectedValue:默认的选择值
常见问题和使用技巧
常见问题:在中了联动下拉列表组之后,页面的回送会引发服务器端掷出“Invalid postback or callback argument”的异常,服务器端也无法取得每个下拉框表中的条目?
使用技巧:我们可以在web.config中加入<pages enableEventValidation="true" />或者在当前页面注册<%@ Page Language="C#" EnableEventValidation="false" %>这样会导至应该程序的安全性。
-------------------------------------------------------
注意CascadingDropDownr控件中的Category设置,Category主要就是为你CascadingDropDownr控件对应的下拉列表控件选定的值取个名字,好区分是下拉列表的值,所以这个得取的不一样。ServiceMethod主要就是对应WebSerivce的方法了,指明当前CascadingDropDown控件使用哪个WebSerivce中的方法,其它的么就不细说了。
-------------------------------------------------------------
一。实现两级联动
前台脚本:
---------------------------<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Label ID="Label1" runat="server" Text="学院"></asp:Label>
<asp:DropDownList ID="ddlstXy" runat="server" Height="16px" Width="109px">
</asp:DropDownList>
<cc1:CascadingDropDown ID="CasdropdownXy" runat="server"
TargetControlID =ddlstXy
LoadingText="加载中。。。"
ServiceMethod="BindCollegeDropDownList"
ServicePath ="~/WebService/AutoCompleteService.asmx"
PromptText="--请选择--"
Category=jxdw >
</cc1:CascadingDropDown>
<asp:Label ID="Label2" runat="server" Text="专业"></asp:Label>
<asp:DropDownList ID="ddlstZy" runat="server" Height="17px" Width="113px" AutoPostBack="True" >
</asp:DropDownList>
<cc1:CascadingDropDown ID="CasdropdownZy" runat="server"
ParentControlID="ddlstXy"
TargetControlID="ddlstZy"
PromptText="--请选择--"
ServiceMethod="BindProfessionalDropDownList"
ServicePath="~/WebService/AutoCompleteService.asmx"
Category =zy>
</cc1:CascadingDropDown>
</div>
------------------------
后台:
WEB服务文件AutoCompleteService.cs
public CascadingDropDownNameValue[] BindCollegeDropDownList(string knownCategoryValues, string category)
{
List<CascadingDropDownNameValue> categorylist = new List<CascadingDropDownNameValue>();
DataTable dt = departmentBll.GetCollegeDownlist();
for (int i = 0; i < dt.Rows.Count; i++)
{
categorylist.Add(new CascadingDropDownNameValue(dt.Rows["dwmc"].ToString(), dt.Rows["dwbh"].ToString()));
}
return categorylist.ToArray();
}
public AjaxControlToolkit.CascadingDropDownNameValue[] BindProfessionalDropDownList string knownCategoryValues, string category)
{
StringDictionary categoryList = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
List<CascadingDropDownNameValue> zylist = new List<CascadingDropDownNameValue>();
ProfessionalBLL professionalBll = new ProfessionalBLL();
string strWhere = "jw_ssdwbh='" + categoryList["jxdw"] + "'";
DataTable dt = professionalBll.GetProfessionalByWhere(strWhere);
for (int i = 0; i < dt.Rows.Count; i++)
{
zylist.Add(new AjaxControlToolkit.CascadingDropDownNameValue(dt.Rows["zymc"].ToString(), dt.Rows["zybh"].ToString()));
}
return zylist.ToArray();
}--------------------------------------------------------------