raffraichir gridview avec datasource
Bonjour,
Je suis confronté à un problème qui peut paraître simple mais je bloque depuis plus d'un jour.
J'ai donc un SPGridview chargée avec un objectDataSource.
J'arrive à la charger et utiliser un paging mais lorsque je filtre sur le header de la grille, ça sélectionne la valeur de filtre mais ça reste sur la page et si je change de page mon filtre n'est pas pris en compte.
J'ai donc mon event ObjectDataSourceFilteringEventHandler, je modifie mon datatable en fonction du filter mais comment faire en sorte que la grille se recharge?
voilà mon objet datasource initialisé
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| ds = new ObjectDataSource();
ds.ID = "myDataSource";
ds.TypeName = t.AssemblyQualifiedName;
ds.SelectMethod = "GetTable";
ds.SelectCountMethod = "GetNbRows";
ds.EnablePaging = true;
ds.MaximumRowsParameterName = "maxrow";
ds.StartRowIndexParameterName = "startrow";
ds.SortParameterName = "sortcol";
ds.ObjectCreating += new ObjectDataSourceObjectEventHandler(ds_ObjectCreating);
ds.Filtering += new ObjectDataSourceFilteringEventHandler(ds_Filtering);
myGrid.DataSourceID = "myDataSource"; |
Voici ma fonction qui se déclenche pour le filtre, si je décommente mygrid.databind() ça boucle
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| private DataTable GetData()
{
string strKey = GetSearchCriteria();
querysearch = strKey;
try
{
if (!string.IsNullOrEmpty(strKey))
{
if (this.Page != null && ds != null)
{
Utils.writeDBLog("", "", "ds.FilterExpression: " + ds.FilterExpression + "- isPostBack? " + this.Page.IsPostBack.ToString());
if (string.IsNullOrEmpty(ds.FilterExpression))
{
string[] splitStr = ds.FilterExpression.Split('=');
string newSearch = string.Empty;
if (splitStr.Length >= 2)
newSearch = splitStr[0].Trim() + ":" + splitStr[1].Trim() ;
strKey = newSearch + " " + strKey;
}
}
// get the query and settings service proxy
SearchQueryAndSiteSettingsServiceProxy settingsProxy = SPFarm.Local.ServiceProxies.GetValue<SearchQueryAndSiteSettingsServiceProxy>();
// get the search service application proxy by name
SearchServiceApplicationProxy searchProxy = settingsProxy.ApplicationProxies.GetValue<SearchServiceApplicationProxy>("Search Service Application");
// create QueryManager and LocationList objects
QueryManager queryManager = new QueryManager();
LocationList locationList = new LocationList();
// add the federated location we want
Location localSearchLocation = new Location("LocalSearchIndex", searchProxy);
// set the start page and page size
localSearchLocation.ItemsPerPage = Convert.ToInt32(itemPerPage);
localSearchLocation.StartItem = (currentPage * Convert.ToInt32(itemPerPage)) + 1;
if (oGrid!= null)
{
if (currentPage != oGrid.PageIndex)
{
currentPage = oGrid.PageIndex;
}
}
// add our managed properties
localSearchLocation.RequestedProperties = new System.Collections.Specialized.StringCollection();//{ "title", "id" };
localSearchLocation.RequestedProperties.AddRange(queryCol.Split(';'));
// add the Location to the LocationList
locationList.Add(localSearchLocation);
// set the query
queryManager.UserQuery = strKey.Trim();
queryManager.Add(locationList);
queryManager.IsTriggered(locationList);
// make the call to search
XmlDocument xmlDocument = queryManager.GetResults(locationList);
nbResult = localSearchLocation.TotalResults;
DataTable dtTemp = ConvertXmlDocumentToDataTable(xmlDocument);
myDataTable = new DataTableWrapper(dtTemp, nbResult);
//oGrid.DataBind();
return dtTemp;
}
}
catch (Exception ex)
{
Utils.writeDBLog("GetData", "error", ex.Message + " - " + ex.StackTrace);
}
return new DataTable();
} |
Si vous aviez un on tuto de comment reloader une grille en fonction de la datasource
Merci