iSeller Commerce
iSeller POS Retail
iSeller POS F&B
iSeller POS Express
Crosslight
WebUI
ClientUI
What's New
Download Trial
Web Solution
Mobile Solution
Enterprise Solution
Custom Development
Blog
Community
Latest Development Blogs
ForumPostTopic
Browse By Tag
Hi Dev team,
One of the core requirements of my project is to save the template (the choice of the columns to display with filter, sort, group options). I have a web grid and a save button on the web-page. I am doing the following to bind the web grid with the data coming from Oracle 11G :
protected void gridView_InitializeDataSource(object sender, ISNet.WebUI.WebGrid.DataSourceEventArgs e)
{
if(_resultSet != null)
e.DataSource = _resultSet.Tables[0];
}
where, _resultSet is a dataset with the data coming from the database.
protected void gridView_PrepareDataBinding(object sender, ISNet.WebUI.WebGrid.DataSourceEventArgs e)
if (IsPostBack && !gridView.IsFlyPostBack)
if (_resultSet != null)
foreach (DataColumn dcol in _resultSet.Tables[0].Columns)
WebGridColumn col = new WebGridColumn();
col.DataMember = dcol.ToString();
col.Caption = dcol.ToString();
gridView.RootTable.Columns.Add(col);
//gridView.RootTable.DataMember
gridView.RetrieveStructure();
Then, I am manipulating the column positions and adding some filters and grouping. Everything works fine till then. After that when I call the Button Save click event to save the changes in the webgrid, it doesnt write the changes in the webgrid, instead just writes the original state of the webgrid (before changes in the column positions and filtering, grouping).
protected void btnSave_Click(object sender, EventArgs e)
if (gridView.DataSource != null)
gridView.SaveTablesStructureToXml(Server.MapPath("layout.xml"));
On top of it, after the postback that happens due to button click event, I lose the state of the grid and the grid shows the data without the filtering, grouping, change in the column position.
Please suggest me how to save the table structure of the grid in the xml as well as maintaining the state of the grid after post back. Due to dynamic nature of the data coming from the database, I can not make Strongly typed datatable to bind the data to the grid.
Thanks
Udy
Hi Udayan,
Basically to save a table structure in some state, you have to save the structure when it's on the right structure which you want. Then you should use LoadTablesStructure method to load the structure which you saved before (or based on table structure file).
For a simple sample, you can create a WebGrid then Bind the data and add 2 button to save and load the structure. Next, on button1 and button2 click event, please follow the snippet code above.Attached is a simple runable sample that show you how to save and load the table structure in WebGrid.
Please let me know if you still unable to save and load the table structure in WebGrid.
Thanks.Riendy
Hi Udayan,You did well to save the table structure of WebGrid. You can save the table structure as simple as that. But, if you want to show the WebGrid in to the saved structure, you have to load the structure. Then, if you want to show the data as well, you have to rebind the data. Please use this code to show your gridView into the saved state.
gridView.LoadTablesStructureFromXml(Server.MapPath("layout.xml")); gridView.RebindDataSource();
Hope this helps.Riendy
Riendy,
Thanks for the quick reply. But I am not able to save the correct table structure to the XML. It is saving the default structure that was bound to the grid initially. Following is the scenario-
a) I bind the dataset to the grid using OnInitialize and PrepareDatabinding events.
b) I change the column positions. (No flypostback happens)
c) I click the save button to save the new structure.
The saved xml doesnt contain the information about the change in the column positions, but instead saves the original structure.
Please suggest how to save the new table structure with new column position information.
Hi Udayan,First of all, I am sorry for my mistake. You should not use SaveTablesStructureToXml and LoadTablesStructureToXml, you have to use SaveTablesStructure and LoadTablesStructure.
Let me assist you for a simple sample to save a table structure. After you bind the data into WebGrid, please add 2 buttons. Then add the codes bellow to each button.
protected void Button1_Click(object sender, EventArgs e) { WebGrid1.SaveTablesStructure(Server.MapPath("SampleLayout.xml")); // you can also use another file (i.e .isl file) // WebGrid1.SaveTablesStructure(Server.MapPath("SampleLayout.isl")); } protected void Button2_Click(object sender, EventArgs e) { WebGrid1.LoadTablesStructure(Server.MapPath("SampleLayout.xml")); //WebGrid1.LoadTablesStructure(Server.MapPath("SampleLayout.isl")); WebGrid1.RebindDataSource(); }
Regards.Riendy
Thanks for the reply Riendy.
After I change the position of the columns inside the webgrid from the UI and then call Button1_Click event, I am not able to save the new structure. It is taking the original structure.
For example - say my grid is bound to a datatable with two columns A and B, with A at position 0 and B at position 1. when I swap the column-positions on the UI and then call the Button1_click event, the xml/isl file still shows the position of the column A as 0 and B as 1. It should show A as 1 and B as 0.
Please assist.
or
Choose this if you're already a member of Intersoft Community Forum. You can link your OpenID account to your existing Intersoft Social ID.
Choose this if you don't have an Intersoft account yet. Your authenticated OpenID will be automatically linked to your new Intersoft account.
Enter your Wordpress Blogname