SPDataSource for asp gridView returns nothing?
-
09-12-2019 - |
Question
I'm binding my SPDataSource to an ASP:DataGrid but it returns empty gridview not filled. Here's my aspx file
<SharePoint:SPDataSource runat="server" ID="SPTypes" DataSourceMode="ListItem" UseInternalName="true">
</SharePoint:SPDataSource>
<asp:gridView ID="GV" runat="server" DataKeyNames="Title" AutoGenerateColumns="False" AllowPaging="true" >
<columns>
<asp:boundfield DataField="Title" HeaderText="Title">
</asp:boundfield>
</columns>
</asp:gridView>
and here's the code behind
SPList corrList = getSelectedList("Correspondance");
SPWeb web = SPContext.Current.Web;
SPList taskList = web.Lists["Tasks"];
SPTypes.List = taskList;
SPTypes.SelectCommand = "<Where><And><Eq><FieldRef Name=\"Title\"/>" +
"<Value Type=\"Text\">Document interne</Value></Eq><Eq><FieldRef Name=\"Fonction\"/>" +
"<Value Type=\"Text\">GenerateChrono</Value></Eq></And></Where>";
GV.DataSource = SPTypes;
GV.DataBind();
I checked the query and it returns many items I even tried to put the query this way :
SPTypes.SelectCommand = "<Query><Where><And><Eq><FieldRef Name=\"Title\"/>" +
"<Value Type=\"Text\">Document interne</Value></Eq><Eq><FieldRef Name=\"Fonction\"/>" +
"<Value Type=\"Text\">GenerateChrono</Value></Eq></And></Where></Query>";
PS title is the internal name I want to retrieve !
Solution
Glolita,
Use SPGridView instead of ASP:GridView...
Here is a nice article: How to use the SPGridView filter together with a SPDataSource
I also noticed in every example in CAML before <Query>
they are using <View>
, but I don't know if this is really the problem... can you please try that as well
Also,
SPTypes.DataSourceMode="List"
Hope this resolves the issue!
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange