質問

SharePoint 2010でスプライストを照会し、対応するグリッドビューを入力しています。

<asp:DataGrid runat="server" ID="gridView" AutoGenerateColumns="false" AlternatingRowStyle-BackColor="ActiveBorder" Width="95%" GridLines="Vertical" AllowPaging="true" PageSize="30" CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt" >
    <Columns>
<asp:BoundColumn DataField="ID"></asp:BoundColumn>
<asp:BoundColumn DataField="Title"></asp:BoundColumn>
<asp:HyperLinkColumn DataTextField="Name" ></asp:HyperLinkColumn>
<asp:BoundColumn DataField="Surname"></asp:BoundColumn>
<asp:BoundColumn DataField="email"></asp:BoundColumn>
</columns>
</gridview>
.

このコードを使用する場合は、グリッドビューと共にこれを使用するとき、スプラストにあるすべての項目を表示できるようにすることができます。しかし、私はリストから特定のデータのみを表示できるようにする必要があります。

            Guid webId = web.ID;
            SPListItemCollection items = list.Items;

            SPList currentTestList = web.Lists[listGuid];

            // query 
            SPQuery oQuery = new SPQuery();
            oQuery.ExpandRecurrence = true;

            oQuery.Query = @"
                <Where>
                    <Eq>
                        <FieldRef Name='Name' />
                        <Value Type='Text'>Adrian</Value>
                    </Eq>
                </Where>
                ";
            gridView.DataSource = list.GetItems(oQuery);
            gridView.DataBind();
.

まだ実行時には、選択されたデータソースに「姓」が見つかりませんでした」とは、次の問題が発生します。コードの何が問題になっているのかを誰かに見せてもらえますか?または私は何かを欠けていますか?「getDatable()」を使用するとうまく機能しますが、一方でリストをフィルタリングするとリストされたエラーが発生します。

更新


指示されたまだ同じエラーがまだ持続しているように表示フィールドを更新しました 現在のコード:

SPQuery oQuery = new SPQuery();
                oQuery.ExpandRecurrence = true;

                oQuery.Query = @"
                    <Where>
                        <Eq>
                            <FieldRef Name='Name' />
                            <Value Type='Text'>Adrian</Value>
                        </Eq>
                    </Where>
                    ";

                oQuery.ViewFields = @"<FieldRef Name='Name' /><FieldRef Name='Surname' /><FieldRef Name='email' /><FieldRef Name='ID' /><FieldRef Name='Title' />";
                oQuery.ViewFieldsOnly = true;
                //binding it to grid view

                SPListItemCollection filteredList = list.GetItems(oQuery);
                gridView.DataSource = filteredList;
                //gridView.DataSource = list.GetItems(oQuery);
                gridView.DataBind();
.

役に立ちましたか?

解決

Try using SPListItemCollection.GetDataTable like this:

var dt = list.GetItems(oQuery).GetDataTable();
gridView.DataSource = dt;

When you just use list.GetItems(oQuery) as the DataSource what the GridView gets is a SPListItemCollection which it doesn't understand, but it's an IEnumerable which it understands. So now the GridView can enumerate the datasource and get its items back, these are of type SPListItem. The GridView then tries to get each column value as either a field or property of the item it processes. The is OK for ID, Title and Name as these all exists as properties on SPListItem, but there is no property SPListItem.SurName you have to use SPListItem["SurName"] but the GridView doesn't know that.

When you use list.GetItems(oQuery).GetDataTable() as the DataSource what the GridView gets is a DataTable and the GridView knows how to access the Rows and Columns of that.

他のヒント

Are you certain that 'Surname' is the proper internal name of the field? The internal name is what needs to be used during queries.

To quickly find out, you can easily inspect the list using powershell:

$url = "http://www.yoursharepointsite.com/mysite"
$listname = "YourListName"

$site= SPSite ($url) 
$web=$site.OpenWeb() 
$list=$web.Lists[$listname] 
$list.Fields |select ID, title, internalname
ライセンス: CC-BY-SA帰属
所属していません sharepoint.stackexchange
scroll top