列表: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

相关文章:

  • 2021-11-07
  • 2021-06-06
  • 2022-03-10
  • 2021-11-23
  • 2022-01-07
  • 2021-11-19
  • 2022-02-20
  • 2021-11-29
猜你喜欢
  • 2021-09-27
  • 2021-10-08
  • 2022-12-23
  • 2021-12-10
相关资源
相似解决方案