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
I have webgrid with all columns that can be contained in datasource, defined in markup. I don't know in advance which columns will come from database so I have to have them all. If I add them from code behind(which old version of application did) I'd have over 2000 lines of code, and now I have about 160 of them because that's how many possible columns exist. I am binding grid to datasource, and of course, if column defined in webgrid doesn't exist in datasource, databinding fails. So what I'm doing in PrepareDataBinding event is check for all columns in grid, if they have their pair in datasource. If not the column is removed from grid's column collection.
For Each col As WebGridColumn In gridZaposleni.RootTable.Columns colName = col.Name colMember = col.DataMember If Not dt.Columns.Contains(colMember) Then gridZaposleni.RootTable.Columns.Remove(col) End If Next
However, this doesn't work because the application fails as it comes to first column that doesn't have it's pair in datasource:
"Can't find DataColumn with name 'Company' in the specified datasource".
I also tried, instead of removing column, setting it's Bound and Visible properties to false. That works, but then I have the grid loading 160 columns, and when I have grouped col's, expanding them takes ages.
There is option to bind grid dynamically to datasource and make it create all columns by itself, but this doesn't work for me because, some columns have formating on them like width, forecolor etc.
My question is - why isn't my first option, with removing columns, working, and how to solve this problem?
Hi Bernard,
thank you for your answer. It's funny that you should suggest this solution, since I had an epifany last night and thought of the same one. I already implemented this, and also thought this could be a performance issue, but now, since you proposed the same, I see that there is no smarter solution than this. Thank you again.
Regards,
Nikola
Hi Nikola,
Glad that you have solved your problem. However in my solution, there are many looping that happen for each column. If you have any further question, please don't hesitate to ask us.
Regards,Bernard
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