Exemplo n.º 1
0
        public override void InitControl()
        {
            string          keyword = Control.Params["keyword"];
            CategoryHelper  helper  = HelperFactory.Instance.GetHelper <CategoryHelper>();
            List <Category> col     = helper.GetChildrenListByKeyword(keyword);//二级

            Field1DropDownList.DataSource     = col;
            Field1DropDownList.DataTextField  = "Name";
            Field1DropDownList.DataValueField = "ID";
            Field1DropDownList.DataBind();
            Field1DropDownList.Items.Insert(0, new ListItem("请选择", ""));
            Field1DropDownList.SelectedValue = Value as string;

            Field1DropDownList.Attributes.Add("onchange", "getSubcate(this,1,'ID')");
            Field2DropDownList.Attributes.Add("onchange", "getSubcate(this,2,'KeyWord')");
            Field3DropDownList.Attributes.Add("onchange", "subcateChange('" + Field3DropDownList.ClientID + "',3)");


            //已有内容还原
            if (Value != null)
            {
                string keywordSubcate = Value.ToString();
                Field3Hidden.Value = keywordSubcate;
                List <Category> colThreecates = helper.GetSiblingListByKeyword(keywordSubcate);

                if (colThreecates != null)
                {
                    Field3DropDownList.DataSource     = colThreecates;
                    Field3DropDownList.DataTextField  = "Name";
                    Field3DropDownList.DataValueField = "KeyWord";
                    Field3DropDownList.DataBind();
                    Field3DropDownList.Items.Insert(0, new ListItem("请选择", ""));

                    Category parent = helper.GetCategory(colThreecates[0].ParentID);

                    List <Category> colTwoSubcates = helper.GetSiblingListByKeyword(parent.KeyWord);
                    Category        parentOne      = helper.GetCategory(colTwoSubcates[0].ParentID);

                    Field2DropDownList.DataSource     = colTwoSubcates;
                    Field2DropDownList.DataTextField  = "Name";
                    Field2DropDownList.DataValueField = "ID";
                    Field2DropDownList.DataBind();
                    Field2DropDownList.Items.Insert(0, new ListItem("请选择", ""));

                    //默认选中索引
                    int parentSelectIndex = colTwoSubcates.FindIndex(p => p.ID == parent.ID) + 1;         //二级

                    int subSelectedIndex = colThreecates.FindIndex(p => p.KeyWord == keywordSubcate) + 1; //三级

                    int parentOneSelectIndex = col.FindIndex(p => p.ID == parentOne.ID) + 1;              //一级

                    Field3DropDownList.SelectedIndex = subSelectedIndex;
                    Field2DropDownList.SelectedIndex = parentSelectIndex;
                    Field1DropDownList.SelectedIndex = parentOneSelectIndex;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 绑定数据(xml)
        /// </summary>
        void BindXmlData()
        {
            ICascadeDataProvider provider = GetProvider();

            Field1DropDownList.DataSource     = provider.QuryFirstLevel("");
            Field1DropDownList.DataTextField  = "key";
            Field1DropDownList.DataValueField = "value";
            Field1DropDownList.DataBind();
            string nodesName      = Control.Params["NodesName"];
            string attributesName = Control.Params["AttributesName"];

            Field1DropDownList.Attributes.Add("onchange", "ThreeCascadeField2('" + Field1DropDownList.ClientID + "',this.value,'" + Field2DropDownList.ClientID + "','" + field2TextMapping + "','" + field2ValueMapping + "','" + field1ValueMapping + "','" + tableName + "','" + Field3DropDownList.ClientID + "','" + field3TextMapping + "','" + field3ValueMapping + "','" + emptyText + "','" + dataSourceType + "','" + Control.Params["data"] + "','" + nodesName + "','" + attributesName + "')");
            this.Field2DropDownList.Attributes.Add("onchange", "ThreeCascadeField3('" + Field1DropDownList.ClientID + "',this.value,'" + Field3DropDownList.ClientID + "','" + field3TextMapping + "','" + field3ValueMapping + "','" + field2ValueMapping + "','" + field1ValueMapping + "','" + tableName + "','" + emptyText + "','" + dataSourceType + "','" + Control.Params["data"] + "','" + nodesName + "','" + attributesName + "')");
            Field1DropDownList.Items.Insert(0, new ListItem("请选择", ""));
            Field1DropDownList.SelectedValue = field1DataField.Value == null ? "" : field1DataField.Value.ToString();
            if (!String.IsNullOrEmpty(Field1DropDownList.SelectedValue))
            {
                Field2DropDownList.DataSource     = provider.QuerySecondLevel(field1DataField.Value.ToString());
                Field2DropDownList.DataTextField  = "key";
                Field2DropDownList.DataValueField = "value";
                Field2DropDownList.DataBind();
                if (!string.IsNullOrEmpty(emptyText))
                {
                    Field2DropDownList.Items.Insert(0, new ListItem("请选择", ""));
                }
                if (field2DataField.Value != null)
                {
                    Field2DropDownList.SelectedValue = field2DataField.Value == null ? "" : field2DataField.Value.ToString();
                }
            }
            if (!String.IsNullOrEmpty(Field2DropDownList.SelectedValue))
            {
                Field3DropDownList.DataSource     = provider.QueryThirdLevel(field1DataField.Value.ToString(), field2DataField.Value.ToString());
                Field3DropDownList.DataTextField  = "key";
                Field3DropDownList.DataValueField = "value";
                Field3DropDownList.DataBind();
                if (!string.IsNullOrEmpty(emptyText))
                {
                    Field3DropDownList.Items.Insert(0, new ListItem("请选择", ""));
                }
                if (field3DataField.Value != null)
                {
                    Field3DropDownList.SelectedValue = field3DataField.Value == null ? "" : field3DataField.Value.ToString();
                }
            }
        }