I'm developing a web-part for SharePoint 2010.
I've to sort a SPGridView
so I use SortExpression
.
I execute a CAML query in this way and then I bind data to SPGridView
:
SPQuery query = new SPQuery();
query.RowLimit = 30;
query.Query = "<OrderBy><FieldRef Name=\"" + sortColumn + "\" Ascending=\"" + sortDir + "\" /></OrderBy>";
query.ViewFields = "<FieldRef Name=\"Title\" />" +
"<FieldRef Name=\"DocIcon\" />" +
"<FieldRef Name=\"Ragione_x0020_Sociale\" />" +
"<FieldRef Name=\"Tipo_x0020_Protocollo\" />" +
"<FieldRef Name=\"Data_x0020_Protocollo\" />" +
"<FieldRef Name=\"Formato_x0020_Documento\" />" +
"<FieldRef Name=\"Utilizzatore_x0020_Interno\" />" +
"<FieldRef Name=\"Note\" />" +
"<FieldRef Name=\"Descrizione\" />";
//query.QueryThrottleMode = SPQueryThrottleOption.Override;
string listName = "Protocolli";
SPList list = SPContext.Current.Web.Lists[listName];
//list.EnableThrottling = false;
if (!string.IsNullOrEmpty(pagingInfo))
{
SPListItemCollectionPosition position = new SPListItemCollectionPosition(pagingInfo);
query.ListItemCollectionPosition = position;
}
SPListItemCollection collection = list.GetItems(query);
grdProtocolli.DataSource = collection.GetDataTable();
grdProtocolli.PagerTemplate = null; // Must be called after Controls.Add(oGrid)
grdProtocolli.DataBind();
sortColumn
is:
if (ViewState["SortExpression"] == null)
{
sortColumn = "Data_x0020_Protocollo";
}
else
{
sortColumn = ViewState["SortExpression"].ToString();
}
Data_x0020_Protocollo
is a field that currently exists.
Now, trying to execute my web-part I receive this error:
0x0AB0 SharePoint Foundation Runtime tkau Unexpected System.ArgumentException: Impossibile trovare un campo con il nome "Data_x0020_Protocollo". at Microsoft.SharePoint.SPFieldCollection.GetFieldByDisplayName(String strDisplayName, Boolean bThrowException)
"Impossibile trovare un campo con il nome..." is translated like "Impossible to find a field with name"
If I use the display name Data Protocollo
I don't get the error anymore (and I can see the GridView
), but sorting is not working.
Any suggestions?