SPQuery如何消除重复记录(实现联动性)

实现大类与小类的联动性

        private void BindIncidentCategory()
        {
            using (SPSite site = new SPSite(rootsiteurl))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPList list = web.Lists["IncidentCategory"];
                    SPListItemCollection listitem = list.Items;
                    DataTable dt = listitem.GetDataTable();
                    DataView dvSort = new DataView(dt);
                    string[] colName = new string[] { "CategoryName" };
                    DataTable dtLargeSort = dvSort.ToTable(true, colName);
                    DropDownListIncidentCategory.DataValueField = "CategoryName";
                    DropDownListIncidentCategory.DataValueField = "CategoryName";
                    DropDownListIncidentCategory.DataSource = dtLargeSort;
                    DropDownListIncidentCategory.DataBind();
                  
                   BindIncidentSubCategory(DropDownListIncidentCategory.SelectedItem.Text);
                    
                }
            }
        }

  
        private void BindIncidentSubCategory(string IncidentCategory)
        {
            using (SPSite site = new SPSite(rootsiteurl))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPList list = web.Lists["IncidentCategory"];
                    SPQuery query = new SPQuery();
                    query.Query = "<Where><Eq><FieldRef Name='CategoryName'/><Value Type='Text'>"+IncidentCategory+"</Value></Eq></Where>";
                    SPListItemCollection listitem = list.GetItems(query);
                    DataTable dt = listitem.GetDataTable();
                    DropDownListIncidentSubCategory.DataTextField = "SubCategoryName";
                    DropDownListIncidentSubCategory.DataValueField = "SubCategoryName";
                    DropDownListIncidentSubCategory.DataSource = dt;
                    DropDownListIncidentSubCategory.DataBind();
                }
            }
        }
 
   protected void DropDownListIncidentCategory_SelectedIndexChanged(object sender, EventArgs e)
   {
        BindIncidentSubCategory(DropDownListIncidentCategory.SelectedItem.Text.Trim());
   }

注意要把DropDownListIncidentCategory中AutoPostBack属性设成true

转载于:https://www.cnblogs.com/masahiro/archive/2011/05/23/10129164.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值