剑花 烟雨

   江南  好 风景旧曾谙 日出江花红胜火 春来江水绿如蓝 能不忆东北

理想中的建筑师应该是一个诗人、数学家、精通历史、精通心理学、熟悉音乐、了解医学、还要具备天文学和计算的基本知识。
                                                                                                                         ------------------公元前25年,罗马建筑学家Vitruvius
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Ajax Controls Tookite :CascadingDropdownList Attention Please

Posted on 2008-04-11 16:17  落花人独立  阅读(777)  评论(1编辑  收藏  举报
在使用CascadingDropdownList的时候需要注意的问题:
  (1)只能通过Web Service的方式来使用这个控件
 (2)创建的Web Service 如下
[System.Web.Script.Services.ScriptService]
[WebService(Namespace 
= "http://tempuri.org/")]
[WebServiceBinding(ConformsTo 
= WsiProfiles.BasicProfile1_1)]
public class BasicTypes : System.Web.Services.WebService
{

    
public BasicTypes()
    {

        
//Uncomment the following line if using designed components 
        
//InitializeComponent(); 
    }
    [WebMethod]
    
public AjaxControlToolkit.CascadingDropDownNameValue[] GetDropDownContents(string knownCategoryValues, string category)
    {
        DataTable dt 
= GetDataTable("Select * from BasicType");
        List
<AjaxControlToolkit.CascadingDropDownNameValue> values = new List<AjaxControlToolkit.CascadingDropDownNameValue>();
        
foreach (DataRow dr in dt.Rows)
        {
            values.Add(
new AjaxControlToolkit.CascadingDropDownNameValue(dr["Type"].ToString(), dr["Id"].ToString()));
        }
        
return values.ToArray();
    }
}
注意红色代码部分。
在CascadingDropdownList的Page method方法中,也就是在使用这个控件的页面的后台代码中,调用Web Service中的(3)WebMethod的名字必须与控件中设置的WebMethod相同。如下图中粗体紫色部分所示:
<ajaxToolkit:CascadingDropDown ID="ccdDataTypeParents" runat="server" Enabled="True"
                    ServiceMethod
="GetDropdownParents" ParentControlID=""
                                                 UseContextKey
="True" ServicePath="BasicTypes.asmx"
TargetControlID
="ddlDataTypeParents"
Category
="DataTypeParentsId" PromptText="请选择父类型" 
                                                 LoadingText
="正在载入父类型"  SelectedValue="">     
                                                
</ajaxToolkit:CascadingDropDown>
(4)在PageMethod中的使用方法如下:
[WebMethod]
    [System.Web.Script.Services.ScriptMethod]

    
public static AjaxControlToolkit.CascadingDropDownNameValue[] GetDropdownParents(string knownCategoryValues, string category)
    {
        
return new BasicTypes().GetDropDownParents(knownCategoryValues, category);
    }
注意要加入紫色代码部分。系统会自己生成紫色的部分,但是不同,所以把系统自动生成 的替换掉就行了(没有替换的我没有试过,只是目前这样做可以工作)。

当出现500错误的时候,核对一下上面所讲的注意事项。

count hit
欢迎您到紫阁阳光坐客