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,
I am using intersoft web grid and this grid has 10 columns. All columns are assigned statically i.e. column is created in grid itself.
Now, I want to move column1 and its value from position 1 to 5 using c# code (code behind) but there is no property available in intersoft web grid to move column and its value.
Please suggest how to move column and its value from one position to another position.
Note: This is my requirement that column should be created statically.
Thanks
Sachin
Hello Sachin,
To move column and its value from one position to another position you can change datamember and caption. Or you can get the ColumnCollection first, then remove and insert to the desired position.
You can see the snippet code bellow
protected void WebGrid1_PrepareDataBinding(object sender, ISNet.WebUI.WebGrid.DataSourceEventArgs e)
{
WebGrid1.RetrieveStructure();
// exchange column index 5 to column index 0
string Member;
string caption;
// exchange DataMember column index 5 to column index 0
Member = WebGrid1.RootTable.Columns[5].DataMember;
WebGrid1.RootTable.Columns[5].DataMember = WebGrid1.RootTable.Columns[0].DataMember;
WebGrid1.RootTable.Columns[0].DataMember = Member;
// exchange Caption column index 5 to column index 0
caption = WebGrid1.RootTable.Columns[5].Caption;
WebGrid1.RootTable.Columns[5].Caption = WebGrid1.RootTable.Columns[0].Caption;
WebGrid1.RootTable.Columns[0].Caption = caption;
}
-----------------------------------------------------------------------------------------------
WebGridColumnCollection columnCollection = WebGrid1.RootTable.Columns;
// move ContactName column to the 1st position
WebGridColumn contactName = columnCollection.GetNamedItem("ContactName");
columnCollection.Remove(contactName);
columnCollection.Insert(0, contactName); // 0 is an index
Hope this helps.
Regards,
Riendy
As you suggested that first remove the column and then insert the column at specific position. I have created a sample and moving two columns from their position but only column header moving from their position, not data move.
My requirement is that move column header and its data from their position to another position.
Please have a look on attached sample and let me know how to achieve this functionality.
Regarding to your sample, there is no mistake in moving column header and its data from their position to another position. But you have called a method in incorrect event. This issue show due move() method exist on preRender Event. To set the structure of WebGrid (in this case to fix the issue), you have to set (call method move()) in prepareDataBinding event. Then, to set a dataSource, I suggest to set it at InitializeDataSource event.
Attached is your sample which I modified.
Hope this helps.Riendy
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