This is a migrated thread and some comments may be shown as answers.

GridSettingsPersister

2 Answers 196 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jan
Top achievements
Rank 1
Jan asked on 21 Feb 2011, 11:43 PM
Hello!

Do you have a sample app of the GridSettingsPersister class extended to store the settings in asp.net profile?
I have tried this sample http://www.telerik.com/community/code-library/aspnet-ajax/grid/storing-multiple-grid-settings-in-database-via-profile.aspx but I would like to use the GridSettingsPersister class instead because it saves columns shown for instance.

Thank you!

Jan

2 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 25 Feb 2011, 09:46 AM
Hi Jan,

The GridSettingsPersister exports the saved settings in a simple string format. You can save it in any persistence medium of your choice. We do not have an example saving to the ASP.NET profile in particular, and it is beyond the scope of the GridSettingsPersister object.

Veli
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Jan
Top achievements
Rank 1
answered on 01 Mar 2011, 11:11 AM
Hello Veli!

Thank you for your reply. I managed to figure out a way to do this.
Maybe not the best way to do it but here's my solution if anyone would end up here:

protected override void Render(HtmlTextWriter writer)
{
    base.Render(writer);
    GridSettingsPersister SavePersister = new GridSettingsPersister(mainGrid);
    try
    {
        MembershipUser myUser = Membership.GetUser();
        ProfileCommon myProfile = Profile.GetProfile(myUser.UserName);
        myProfile.GridSettings = SavePersister.SaveSettings();
        myProfile.Save();
    }
    catch (HttpException err)
    {
        SetMessage("ERROR " + err.Message);
    }
}
//
protected void Page_Init(object sender, EventArgs e)
{
    GridSettingsPersister LoadPersister = new GridSettingsPersister(mainGrid);
    try
    {
        MembershipUser myUser = Membership.GetUser();
        ProfileCommon myProfile = Profile.GetProfile(myUser.UserName);
        string settings = myProfile.GridSettings;
        if (settings != null)
        {
            LoadPersister.LoadSettings(settings);
        }
    }
    catch (HttpException err)
    {
        SetMessage("ERROR " + err.Message);
    }
}

Set error message:
private void DisplayMessage(string text)
{
    mainGrid.Controls.Add(new LiteralControl(string.Format("<span style='color:red'>{0}</span>", "STATUS: " + text)));
}
//
private void SetMessage(string message)
{
    gridMessage = message;
}

And in web.config
<profile defaultProvider="MySqlProfileProvider">
    <providers>
        <clear/>
        <add name="MySqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="connAspNetUsers" applicationName="appName"/>
    </providers>
    <properties>
        <add name="GridSettings" allowAnonymous="false" type="String" serializeAs="Binary"/>
    </properties>
</profile>

Thanks

Jan
Tags
Grid
Asked by
Jan
Top achievements
Rank 1
Answers by
Veli
Telerik team
Jan
Top achievements
Rank 1
Share this question
or