zoukankan      html  css  js  c++  java
  • 学习: 实现动态查询列表视图数据(转)

    在实际项目中经常会遇到客户要求查询列表视图要像一般的ASP.NET一样,如果条件简单让他们直接用列表视图筛选功能就可以了。

    如果筛选条件很复杂的话,他们就没办法直接用列表视图筛选功能来实现了,那我们怎么办呢?

    那我们就开发一个查询功能的WebPart,让用户输入查询条件来查询。以下我把最有用的部分发布出来,相信大家都会构造SPQuery查询语句。 

            private void cmdListFiltes_Click(object sender, System.EventArgs e)
            {
                //定义一个SPView
                SPView mView = null;

                //定义一个需要查询的ListViewWebPart,
                //其实SPList显示界面中都是用ListViewWebPart显示的
                ListViewWebPart lvSelect = null;
               
                //构造SPQuery查询字符串,查询字符串
                string sFiltersQuery = getQueryStr();

                //找出你要查询的ListViewWebPart
                //当然你在配置WebPart的时候需要输入查询的ListViewWebPart的
                foreach (WebPart webPart in WebPartManager.WebParts)
                {
                    //判断是否是ListViewWebPart类型
                    if (webPart.GetType() == typeof(ListViewWebPart))
                    {
                        if (webPart.UniqueID == SelectListViewWebPartUniqueID)
                        {
                            lvSelect = webPart as ListViewWebPart;
                            break;
                        }
                    }
                }

                //关键部分
                if (lvSelect != null)
                {
                    //你需要查询的SPList
                    SPList list = SPControl.GetContextWeb(this.Context).Lists[listname];
                    //给SPView赋值
                    mView = list.Views[new Guid(lvSelect.ViewGuid)];
                    //查询之后从那里来回到那里去
                    sSelectViewOrgQuery = mView.Query;
                    //给SPView中
                    mView.Query = sFiltersQuery;
                    //把SPView的SchemaXml赋给ListViewWebPart的ListViewXml
                    lvSelect.ListViewXml = mView.SchemaXml;
                    //回到原始状态,不要改变SPView的SPQuery值
                    mView.Query = sSelectViewOrgQuery;
                }
            }

    希望对大家有所帮助。

    文章来源:http://www.cnblogs.com/SeaBird/archive/2009/11/04/1595641.html

  • 相关阅读:
    监听器
    过滤器
    连接池与分页
    jdbc优化
    jdbc入门
    web开发mysql基础
    自定义标签
    jsp基础
    会话管理入门
    19. Remove Nth Node From End of List C++删除链表的倒数第N个节点
  • 原文地址:https://www.cnblogs.com/LeimOO/p/1781181.html
Copyright © 2011-2022 走看看