GridSettingPersister doesn't work correctly

2 posts, 0 answers
  1. archimede
    archimede avatar
    103 posts
    Member since:
    Jul 2006

    Posted 30 Nov 2010 Link to this post

    Hello,
    in my web application I have a problem using GridSettingsPersister. In the applcation I have different RadGrid and I want let the user modify them (move columns, change column order/visibility/size). So i followed the instruction at http://demos.telerik.com/aspnet-ajax/grid/examples/programming/savinggridsettingsonperuserbasis/defaultcs.aspx.

    I want the user to access a single page where he can choose which RadGrid to modify. After he choses the RadGrid, the application loads the chosen view grid into a panel and let the user modify it. After that we can save the configuration string in database.

    I've used the GridSettingsPersister class of the example.

    My problem is this:
    - I choose the radgrid and load the radgrid to modify into the panel
    - I modify some column visibility  (show only 3 columns for example)
    - I correctly save the settings into db
    - I load the configuration from database string (here all works fine)
    - I add visibility to another column and retry to save
    - Now I load the settings from the database string instead of havinf 4 columns I see all columns of grid (it seems a wrong configuration string has been saved into database)

    I use the following code to:
    -load configuration
    public static void LoadGridConfiguration(RadGrid pRdg, long pIdGruppoUtente, bool loadDefaultString = false)
       {
           GridSettingsPersister gsp = new GridSettingsPersister(pRdg);
     
           using (DMWEntities context = new DMWEntities())
           {
               long idControlloAspx = (from ctrl in context.ControlliAspx
                                       where (ctrl.NomeControllo == pRdg.ID)
                                       select ctrl.IdControlloAspx).SingleOrDefault();
     
               if (idControlloAspx == 0)
               {
                   throw new Exception("Grid Control not defined in database [ControlliAspx]");
               }
     
               var stringaConfigurazioneGruppoUtente = (from pg in context.ProprietaGriglie
                                                        where (pg.IdControlloAspx == idControlloAspx) && (pg.IdGruppoUtente == pIdGruppoUtente)
                                                        select new { pg.StringaConfigurazione, pg.StringaConfigurazioneDefault }).FirstOrDefault();
     
               if (loadDefaultString)
               {
                   gsp.LoadSettings(stringaConfigurazioneGruppoUtente.StringaConfigurazioneDefault);  
               }
               else
               {
                   gsp.LoadSettings(stringaConfigurazioneGruppoUtente.StringaConfigurazione);
               }
           }
       }

    -save configuration
    protected void btnPersistConfiguration_Clicked(object sender, EventArgs e)
        {
            MachinaWeb.ServerControls.RadPageView paginaConComboIdGruppoUtente = (MachinaWeb.ServerControls.RadPageView)((System.Web.UI.Control)MachinaWeb.ServerControls.Utility.FindControlType((Control)sender, typeof(MachinaWeb.ServerControls.RadPageView)));
            MachinaWeb.ServerControls.RadGrid gridUC = (MachinaWeb.ServerControls.RadGrid)((System.Web.UI.Control)MachinaWeb.ServerControls.Utility.FindControlType((Control)sender, typeof(MachinaWeb.ServerControls.RadGrid)));
     
            long selectedGU = long.Parse( ((RadComboBox)paginaConComboIdGruppoUtente.FindControl("blccmbGruppoUtente")).SelectedValue );
     
            //MessageBox.ShowTelerik(Page, this, "Configurazione salvata (Id Gruppo " + blccmbGruppoUtente.SelectedValue + ")");
     
            string gridName = gridUC.ID;
     
            using (DMWEntities context = new DMWEntities())
            {
                long idControlloAspx = (from ctrl in context.ControlliAspx
                                        where (ctrl.NomeControllo == gridName)
                                        select ctrl.IdControlloAspx).SingleOrDefault();
     
                if (idControlloAspx == 0)
                {
                    throw new Exception("Grid Control not defined in database [ControlliAspx]");
                }
     
     
                var propGriglia = (from pg in context.ProprietaGriglie
                                   where (pg.IdControlloAspx == idControlloAspx) && (pg.IdGruppoUtente == selectedGU)
                                   select pg).FirstOrDefault();
     
     
                GridSettingsPersister gsp = new GridSettingsPersister(gridUC);
                string stringaConfigurazioneVista = gsp.SaveSettings();
     
                if (propGriglia == null)
                {
                    //Creates row in database [Proprieta griglie]
                    ProprietaGriglie pgNew = new ProprietaGriglie() { IdGruppoUtente = selectedGU, NomeGriglia = gridName, StringaConfigurazione = stringaConfigurazioneVista, IdControlloAspx = idControlloAspx, DataCreazione = DateTime.Now, DataAggiornamento = DateTime.Now, IdUtente = ((SessionInformation)Session["sessionData"]).IdUtente };
                    context.ProprietaGriglie.AddObject(pgNew);
                    context.SaveChanges();
                }
                else
                {
                    //Updates row [Proprieta griglie]
                    var pg = (from pgUpd in context.ProprietaGriglie
                              where (pgUpd.IdControlloAspx == idControlloAspx) && (pgUpd.IdGruppoUtente == selectedGU)
                              select pgUpd).Single();
     
                    pg.StringaConfigurazione = stringaConfigurazioneVista;
                    context.SaveChanges();
                }
     
            }
        }

    -this is the code behind of my page
    public partial class Configurazione_VisteTabellari : System.Web.UI.Page
    {
        private RadGrid rdg = new RadGrid();
     
        protected void Page_Init(object sender, EventArgs e)
        {
            hfdIdCultura.Value = ((SessionInformation)Session["sessionData"]).IdCultura.ToString();
        }
     
        protected override void InitializeCulture()
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(((SessionInformation)Session["sessionData"]).Cultura);
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(((SessionInformation)Session["sessionData"]).Cultura);
            base.InitializeCulture();
        }
     
     
        protected void Page_Load(object sender, EventArgs e)
        {
            //string resource_ModificareLayoutTabella = (string)GetGlobalResourceObject("Resource", "MessaggioModificaLayoutTabella");
     
            using (DMWEntities context = new DMWEntities())
            {
                if (!String.IsNullOrEmpty(hdfIdMascheraSelezionata.Value))
                {
                    long idMascheraSelezionata = long.Parse(hdfIdMascheraSelezionata.Value);
     
                    string urlVisioneTabellare = (from masc in context.Maschere
                                                  where masc.IdMaschera == idMascheraSelezionata
                                                  select masc.UrlControlloVistaTabellare).Single<string>();
     
     
                    try
                    {
                        RadGridStabilimenti uc = ((RadGridStabilimenti)LoadControl(urlVisioneTabellare));
                        uc.Type = CommonParameters.RadGridType.Configurazione;
                        pnlVistaTabellare.Controls.Clear();
                        pnlVistaTabellare.Controls.Add(uc);
                    }
                    catch (Exception)
                    { }
     
                    //Loads stringa configurazione di default per la grid
                    //RadGrid gridUC = ((IUserControlGrid)pnlVistaTabellare.Controls[0]).GetGrid();
     
                    //if (!Page.IsPostBack)
                    //{
                    //    try
                    //    {
                    //        Utility.LoadGridConfiguration(gridUC, ((SessionInformation)Session["sessionData"]).IdGruppoUtente, true);
                    //    }
                    //    catch (ArgumentNullException)
                    //    {
                    //    }
                    //}
     
                    string selectedGU = (((SessionInformation)Session["sessionData"]).IdGruppoUtente).ToString();
                    blccmbGruppoUtente.SelectedValue = selectedGU;
                    blccmbGruppoUtente.DataBind();
                    //gridUC.DataBind();
                }
            }
        }
     
        protected void rtsPagina_TabClick(object sender, RadTabStripEventArgs e)
        {
            rts_Pagina.SelectedIndex = e.Tab.Index;
            rmp_Pagina.SelectedIndex = e.Tab.Index;
        }
     
        protected void RadGridVisioniTabellari_ItemCreated(object sender, GridItemEventArgs e)
        {
            ////Sets filter's textbox width
            //if (e.Item is GridFilteringItem)
            //{
            //    //30px di differenza rispetto alla larghezza della colonna
            //    GridFilteringItem gridFilteringItem = (GridFilteringItem)e.Item;
            //    ((TextBox)(gridFilteringItem["NomeMaschera"]).Controls[0]).Width = Unit.Pixel((int)(900 - CommonParameters.GridFilterWidthDistances));
            //}
        }
        protected void btnLoadConfiguration_Click(object sender, EventArgs e)
        {
            RadGrid gridUC = ((IUserControlGrid)pnlVistaTabellare.Controls[0]).GetGrid();
            string gridName = gridUC.ID;
            GridSettingsPersister gsp = new GridSettingsPersister(gridUC);
     
            Utility.LoadGridConfiguration(gridUC, long.Parse(blccmbGruppoUtente.SelectedValue));
        }
     
    }



  2. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 02 Dec 2010 Link to this post

    Hi archimede,

    To be able to debug this issue, we are going to need some stripped down runnable project we can run locally. Please, consider opening a regular support ticket where you can send us your project as an attachment.

    Greetings,
    Veli
    the Telerik team
    Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top