zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Android学习---- 十月
    第17章 使用PHP和MySQL实现身份验证
    第13章 MySQL高级编程
    第12章 MySQL高级管理
    第11章 使用PHP从Web访问MySQL数据库
    第10章 使用MySQL数据库
    第9章 创建Web数据库
    第5章 代码重用与函数编写
    NOIP模拟赛-奶牛晒衣服(dry)
    BZOJ1008 /乘法原理+快速幂 解题报告
  • 原文地址:https://www.cnblogs.com/masahiro/p/10129164.html
Copyright © 2011-2022 走看看