Hi Penn,
That KB article is devoted to the XtraGrid - our WinForms control. For the ASpxGridView, please use the methods mentioned in the following help topics:
Save and Restore Layout
How to: Save and Restore the ASPxGridView's Layout
Thanks,
Serge
--------------------
Check if Search Engine is able to answer questions faster than I do!
P.S. By the way, it seems you're using an older build of our components (according to the report's Version field). Please visit our version info page, to learn about the most recent versions of our products, and obtain instructions on how to update them.
Thank you for your quick response. Actually, I had called Sales and finally figured out the difference between Xtra controls (WinForms) and ASPx controls (WebForms). Then I found the pages you mentioned in your responce. I'm still a bit unclear on a couple of issues:
1. Is there a program I can run to automatically update my versions of the controls, etc. to which I am licensed?
2. I saw the Saving/Restoring Manually code but I was wondering
a. What database are the layout strings being saved to? Do I have to create a new table in my database or is this being done internally?
b. Can I present the user with a dropdown ComboBox list of Restorable layouts (gridview data views)?
c. If this is possible, can the names of the strings be made more user-friendly?
d. Can users edit and save, save under a new name or delete these layout strings?
e. In my scenario of a selectable dropdown choice list, how would I passs the e.Parameter == "load" to the CustomCallback method?
f. How owould I delete the layout string?
Does that make sense?
Hello Penn,
> 1. Is there a program I can run to automatically update my versions of the controls, etc. to which I am licensed?
Yes, you can launch the ProjectConverter distributed with all versions of our controls. The detailed information is available in our help article: Upgrade Notes. Simply read our news, and you'll be always be informed about updates.
>2. I saw the Saving/Restoring Manually code but I was wondering
> a. What database are the layout strings being saved to? Do I have to create a new table in my database or is this being done internally?
If you wish, you can create a database with a table of layouts and store them there
>b. Can I present the user with a dropdown ComboBox list of Restorable layouts (gridview data views)?
You can use the ASPxComboBox control and bind it with the datasource (which loads a data from the mentioned database).
>c. If this is possible, can the names of the strings be made more user-friendly?
The ASPxGridView uses a custom format for its layout, which is undocumented. If you wish, you can alow users to store their layouts with custom descriptions.
>d. Can users edit and save, save under a new name or delete these layout strings?
I don't recommend that you modify grid's layout, because if you make it invalid, the ASPxGridView will simply ignore it. The possible suggestion is to allow deleting and adding new layouts.
>e. In my scenario of a selectable dropdown choice list, how would I passs the e.Parameter == "load" to the CustomCallback method?
You should perform callbacks to the ASPxGridView using its client-side ASPxClientGridView.PerformCallback method.
>f. How would I delete the layout string?
It depends on where you wish to remove the layout string. The obvious solution is to remove appropriate records from the mentioned database.
Thanks,
Vest
I'm now ready to incorporate this (save & restore gridview layout) into my application. I have been doing a lot of reading on the website but I'm afraid I'm still a bit confused. Is the layout string automatically generated or do I have to specify each part?
You said I could change the display name for the layout in a dropdown list using an undocumented feature but I'm afraid I don't exactly understand how to set that up. The user is the one who must create the layout and then name it. I would also like for the user to be able to select the fields that would be displayed in the GridView but don't know how to set that up.
In the example I found at:
it asks for a UserID and Database. Does the term Database refer to the type of object or is this where I put the name of the data table that stores the layouts?
I do not want all of these layouts to be user-specific. I need to have the option of keeping some layouts as user-specific and others as available to all users. How might I do that?
I looked for a demo or tutorial on this topic with no luck. If you know of one, I would be happy to study it.
Kind regards, Penn
Hello Penn,
The ASPxGridView (and the ASPxTreeList) layout is a simple string that is built using some internal rules. You don't need to generate it by yourself.
All you need is to store or restore this string when it is required.
Let's assume that a user created a required layout: hid columns, sorted some of them, and grouped, too. And then he wishes to store the resulting layout. The layout can be obtained by demand using the ASPxGridView.LoadClientLayout method. It returns a string describing the entire grid's layout. Then you can store this string elsewhere, display to other users and so on.
To restore the grid's layout, you should call the ASPxGridView.SaveClientLayout method. It performs another job - applies custom layout data to the grid.
I've created a small project that illustrates this feature in action.
By the way, I recommended the ASPxGridView.ClientLayout event, because it is useful in scenarios when you wish to store the layout automatically during user interaction. E.g. when a user opens a page, this event is helpful to retrieve the layout from a database.
Thanks,
Vest
I really apologize for not getting this but I don't understand how to go from the code below to a datafile.
Say, for example, that I have 2 database tables
Table 1 = lu_Layout
LayoutID (tinyint -> byte)
LayoutString (text -> string)
Description (text -> string) = user-defined description of the layout
ContactID (int -> Int32) = linked to the contact who is designated as one of the users
LayoutSourceID (tinyint -> byte)
[links to lu_LayoutSource so that different layouts can be tied to one grid or another (e.g. Organization, Contact, etc.]
IsGlobal (bit -> )
Table 2 = lu_LayoutSource
LayoutSourceID (tinyint -> byte)
LayoutSource (varchar(20) -> string) (ex. Organization, Contact, etc.)
[ASPX]
SQLDataSource: dsOrgLayouts
SELECT lu_Layout.LayoutString, lu_Layout.Description, lu_Layout.ContactID, lu_Layout.IsGlobal, lu_Layout.LayoutID, lu_LayoutSource.LayoutSource, lu_LayoutSource.LayoutSourceID FROM lu_Layout INNER JOIN lu_LayoutSource ON ISNULL(lu_Layout.LayoutSourceID, 1) = ISNULL(lu_LayoutSource.LayoutSourceID, 1) WHERE (lu_Layout.IsGlobal = 1) AND (lu_LayoutSource.LayoutSourceID = 1) OR (lu_Layout.ContactID = 2) AND (lu_LayoutSource.LayoutSourceID = 1)
ASPxComboBox
Textfield=Description
Valuefield=LayoutID
SELECT
Using the code below, I would like to write the layout string to lu_Layout and also pass in the user's user-friendly description of t he layout, the current ContactID (user), the LayoutSourceID and the user's choice of IsGlobal - Yes or No.
I am assuming that "AccountGrid" below refers to the GridView control on my aspx page. I also assume that "filename" below would be "lu+Layout" in my example.
So, is all I have to do is substitute the name of my GridView control and my table in the appropriate places and voila! ?
What I don't understand is where UserID fits in and also why the code has If File.Exists(fileName) for the restoring but the filename is never mentioned for the storing procedure. How does this code know where to store the layout string?
Code from ASPxGridView.ClientLayout Event
Protected Sub ASPxGridView1_ClientLayout(sender As Object,_
e As DevExpress.Web.ASPxClasses.ASPxClientLayoutArgs)
If e.LayoutMode = DevExpress.Web.ASPxClasses.ClientLayoutMode.Saving Then
SaveUserLayoutToDatabase(userID, "AccountGrid", e.LayoutData)
Else
If File.Exists(fileName) Then
e.LayoutData = RestoreUserLayoutFromDatabase(userID, "AccountGrid")
End If
End If
End Sub
I also have a couple of questions on your code (please see below):
1. Protected Sub grid_ClientLayout(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxClasses.ASPxClientLayoutArgs)
2. ' disable callbacks for the ASPxGridView
3.
4. 'if (e.LayoutMode == DevExpress.Web.ASPxClasses.ClientLayoutMode.Saving)
5 ' txt.Text = e.LayoutData;
6. 'else
7. ' e.LayoutData = txt.Text;
8. End Sub
9. Protected Sub btnRestore_Click(ByVal sender As Object, ByVal e As EventArgs)
10. grid.LoadClientLayout(txt.Text)
11. End Sub
12. Protected Sub btnStore_Click(ByVal sender As Object, ByVal e As EventArgs)
13. txt.Text = grid.SaveClientLayout()
14. End Sub
What do you mean by line 2?
Why are lines 4-6 commented out?
Thank you. Penn
Hello Penn,
ASP.NET pages aren't persisted on the server. Each time a callback/postback occurs, the server builds a page from scratch. It restores the original hierarchy, applies the ViewState, posts data and so on. When the ASPxGridView is bound to data, it tries to restore its layout if it is required. The restoration is performed using the ASPxGridView.ClientLayout event. In our help, you can see the code that performs layout saving/restoring automatically.
How does the sample code behave:
When the ASPxGridView needs a fresh layout it raises the ASPxGridView.ClientLayout event. The e.LayoutMode is equal to Loading. There you check that a file (of some name) exists in the file system. If it doesn't exist, you can restore the layout. This is obvious.
When a file exists, you simply restore the layout of an appropriate user for an appropriate grid.
Then the ASPxGridView applies the modified layout (e.g. after you change the column's width) and you should store this layout to a file/database/elsewhere.
You use the same event, check the e.LayoutMode and then store the e.LayoutData wherever it is required.
> What do you mean by line 2?
Use the EnableCallBacks property to disable callbacks for the ASPxGridView. When you do it, you'll see that the LayoutData is saved and restored to an external ASPxTextBox. I commented it only to show what kind of layout the ASPxGridView has.
I think that you don't need automatic layout saving/restoring. Probably you need a layout restoring that can be performed automatically, but saving should be performed on demand (e.g. when a user presses the "Save Layout" button).
Thanks,
Vest
Hi Vest,
Thank you for your quick responses. Although your latest response seemed a long way from the questionns I posed, I'm sure the background and overall pictureyour explanation provided will be very helpful as I work through it. Every discipline has its own syntax and it takes a little getting used to.
I attempted to play around with the code provided in the documentation example but cannot find these two methods. As I understood it, they were in the DevExpress.Web.ASPxGridView namespace but I couldn't find them there and even after importing DevExpress.Web.ASPxGridView into my VB code behind, they are still not available. Could you please explain this?
SaveUserLayoutToDatabase(userID, "AccountGrid", e.LayoutData)
RestoreUserLayoutFromDatabase(userID, "AccountGrid")
Kind regards, Penn
Hello Penn,
These methods are created for demonstration purposes only. One of the methods gets the user ID, the grid's name and the grid's layout values. Then, it somehow saves them to the required data storage.
If you wish, you can store them to the database, or to a text file, or to the Session, browser cookies etc.
This is a general solution to describe how to store/restore a grid's layout. I hope this doesn't confuse you too much, because I'm sure that you know how to manipulate database records programmatically.
Thanks,
Vest
Is your intention to post an answer to your own question?
- If so, then proceed.
- If you simply wanted to post additional information, ask for further clarification, or to just say "Thanks!", please click Leave a Comment.
- If you wish to edit your original question, please use the Edit button in the Toolbox at the top right corner of that entry.
Facebook
Twitter
Google+