• SPquery


    Guid guid = new Guid("{8238B046-EC5F-46B6-8E18-028F77EC2620}");
                SPSite Asite = new SPSite("http://mosslt/");
                SPList list = Asite.RootWeb.Lists[guid];

                SPQuery query = new SPQuery();
               query.Query = @"
                                   <OrderBy>
                                        <FieldRef Name=ID' />
                                   </OrderBy>

                                   <Where>
                                        <Gt>
                                             <FieldRef Name='ID' />
                                             <Value Type='Counter'>0</Value>
                                        </Gt>
                                   </Where>"; //顺序按ID排,条件为ID大于0

                query.ViewFields = @"            
                                      <FieldRef Name='LinkTitle' />
                                      <FieldRef Name='htchange' />
                                      <FieldRef Name='htinfo' />";//要显示在前的三字段,后而会自动回上ID,Created


                this.GridView1.DataSource =list.GetItems(query).GetDataTable();
                this.GridView1.DataBind();

    字段及其它信息可以用Stramit Caml Viewer 2007 查看

    如:

    using (SPWeb oWebsiteRoot = SPContext.Current.Site.RootWeb)
    {
        SPList oList = oWebsiteRoot.Lists["List_Name"];

        SPQuery oQuery = new SPQuery();
        oQuery.ViewFields = "<FieldRef Name='Field1'/>" +
            "<FieldRef Name='Field2'/>";
        oQuery.Query = "<Where><Geq><FieldRef Name='Field2'/>" +
            "<Value Type='Number'>1000</Value></Geq></Where>";
        SPListItemCollection collListItems = oList.GetItems(oQuery);

        foreach (SPListItem oListItem in collListItems)
        {
            Response.Write(SPEncode.HtmlEncode(oListItem.Xml) + "<BR>");
        }
    }

    用法

    using (SPWeb oWebsite = SPContext.Current.Site.AllWebs["Site_Name"])
    {
        SPList oList = oWebsite.Lists["List_Name"];

        SPQuery oQuery = new SPQuery();

        oQuery.ViewXml = "<View><Query><OrderBy><FieldRef Name='ID'/>" +
            "</OrderBy><Where><Or><Geq><FieldRef Name='Field1'/>" +
            "<Value Type='Number'>1500</Value></Geq><Leq>" +
            "<FieldRef Name='Field2'/><Value Type='Number'>500</Value>" +
            "</Leq></Or></Where></Query><ViewFields>" +
            "<FieldRef Name='Title'/>" +
            "<FieldRef Name='Field1'/><FieldRef Name='Field2'/>" +
            "<FieldRef Name='Field3'/><FieldRef Name='Field4'/>" +
            "</ViewFields><RowLimit>100</RowLimit></View>";
        SPListItemCollection collListItemsAvailable = oList.GetItems(oQuery);

        foreach (SPListItem oListItemAvailable in collListItemsAvailable)
        {
            Response.Write(SPEncode.HtmlEncode(oListItemAvailable.Xml) +
              "<BR>");
        }
    }

  • 相关阅读:
    c语言中while循环
    c语言中while循环
    css元素重叠代码
    css指定裁剪区域代码
    css元素重叠代码
    css正常文档布局和元素可见性代码
    css元素浮动代码
    css指定裁剪区域代码
    css正常文档布局和元素可见性代码
    css元素浮动代码
  • 原文地址:https://www.cnblogs.com/IsNull/p/1724802.html
Copyright © 2020-2023  润新知