none
Problem with SPGridView RRS feed

  • Question

  • Hello,

    I created a webpart displaying an SPGridView, this grid is configured by the toolpart of the webpart (I created a dropdownList that contains all Lists, a checkboxList for displaying all Fields of List so user can check fields to see in his grid).
    My problem that I when I put datatable like datasource of my grid I don't have a result. The datatable is a DataTable object that result of CAML Query and I think that there is a problem in noun of columns. I save all checkedbox in a List<String> that I can know fields to display. After I coded my request depending of this list so I think that here is my problem.

    The code of CAML Request
    public DataTable GetData(string nomListe)
            {
                DataTable datatable = new DataTable();
                SPList objSPList=SPContext.Current.Web.Lists[nomListe];
                SPListItemCollection objSPListItemCollection;
                string str = null;
               
                    #region Requête CAML sur la liste sélectionné dans la zone de config
                    SPQuery objSPQuery = new SPQuery();
                    for (int i = 0; i < DisplayFields.Count; i++)
                    {
                        str += @"<FieldRef Name='" + DisplayFields[i] + "' />";
                    }
                    objSPQuery.ViewFields = str;
                    objSPListItemCollection = objSPList.GetItems(objSPQuery);
                    #endregion
    
    
                    #region Affecter la valeur de la requête au grid
                    datatable=objSPListItemCollection.GetDataTable();
                    //datatable.AcceptChanges();
                    #endregion
    
    
                
    
                //catch (Exception E)
                //{
                //    this.Page.Response.Write("<script>alert('" + E.Message + "')</script>");
                //}
    
                return datatable;
            }
    The code of Columns of grid
    public void BindingColumns()
            {
                try
                {
                    for (int i = 0; i < GetData(NomListe).Columns.Count; i++)
                    {
                        BoundField colTitle = new BoundField();
    
                        colTitle.DataField = GetData(NomListe).Columns[i].ColumnName;
    
                        colTitle.HeaderText = GetData(NomListe).Columns[i].ColumnName;
                        this.objSPGridView.Columns.Add(colTitle);
                    }
    
                    
                   
                  
                }
    
                catch (Exception E)
                {
                    this.Page.Response.Write("<script>alert('" + E.Message + "')</script>");
                }
            }
    mardi 7 juillet 2009 14:00