﻿<?xml version="1.0" encoding="utf-8"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Intersoft Community - WebGrid Enterprise - Remove column defined in aspx markup, from server-side</title><link>http://www.intersoftsolutions.com/Community/WebGrid/Remove-column-defined-in-aspx-markup-from-server-side/</link><description /><generator>http://www.intersoftsolutions.com</generator><language>en</language><copyright>Copyright 2002 - 2015 Intersoft Solutions Corp. All rights reserved.</copyright><ttl>60</ttl><item><title>Remove column defined in aspx markup, from server-side</title><link>http://www.intersoftsolutions.com/Community/WebGrid/Remove-column-defined-in-aspx-markup-from-server-side/</link><pubDate>Thu, 23 May 2013 22:59:22 GMT</pubDate><dc:creator>bernard</dc:creator><category>WebGrid</category><category>DataSource</category><category>Server-side</category><category>serverside</category><category>dynamically</category><category>column</category><category>remove</category><category>Unbound</category><category>DataBind</category><category>collection</category><category>datatable</category><category>PrepareDataBinding</category><category>aspx</category><category>server</category><category>side</category><description>Hi Nikola,&lt;div&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;Maybe if you have list of column that you want to delete, we can do it this way. You can list the column that you want to delete in 1 array regarding the privilege that user have in that column. Then in PrepareDataBinding event, you can delete the column that listed in that array. Although, you can change this array like datasource like you did before. Also with this method, you couldn't have to define each 160 column in WebGridColumns. You just need to retrieve the structure then remove the column that you want to delete in WebGrid. I attach my sample here. Hope this helps.&lt;/div&gt;
&lt;div&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;Regards,&lt;br /&gt;Bernard&lt;/div&gt;</description></item><item><title>Remove column defined in aspx markup, from server-side</title><link>http://www.intersoftsolutions.com/Community/WebGrid/Remove-column-defined-in-aspx-markup-from-server-side/</link><pubDate>Thu, 23 May 2013 08:16:48 GMT</pubDate><dc:creator>sinan.biondic@gmail.com</dc:creator><category>WebGrid</category><category>DataSource</category><category>Server-side</category><category>serverside</category><category>dynamically</category><category>column</category><category>remove</category><category>Unbound</category><category>DataBind</category><category>collection</category><category>datatable</category><category>PrepareDataBinding</category><category>aspx</category><category>server</category><category>side</category><description>&lt;p&gt;I have 160 columns, I can't do that for all of them. That's what we did in previous version of application, and that was 2000 lines of code. So there has to be a better way.&lt;/p&gt;</description></item><item><title>Remove column defined in aspx markup, from server-side</title><link>http://www.intersoftsolutions.com/Community/WebGrid/Remove-column-defined-in-aspx-markup-from-server-side/</link><pubDate>Thu, 18 Apr 2013 02:23:05 GMT</pubDate><dc:creator>bernard</dc:creator><category>WebGrid</category><category>DataSource</category><category>Server-side</category><category>serverside</category><category>dynamically</category><category>column</category><category>remove</category><category>Unbound</category><category>DataBind</category><category>collection</category><category>datatable</category><category>PrepareDataBinding</category><category>aspx</category><category>server</category><category>side</category><description>&lt;p&gt;Hi Nikola,&lt;/p&gt;&lt;p&gt;You can achieve this Maybe for this scenario you can use HiddenDataMember property to hide DataMember in other column. Then you can set Visibility of that column to false. I attach the simple sample here. Could you look in my sample and tell me if this sample achieve your scenario or no? Look forward to hear any feedback from you so I can help you further.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Bernard&lt;/p&gt;</description></item><item><title>Remove column defined in aspx markup, from server-side</title><link>http://www.intersoftsolutions.com/Community/WebGrid/Remove-column-defined-in-aspx-markup-from-server-side/</link><pubDate>Wed, 17 Apr 2013 08:22:30 GMT</pubDate><dc:creator>sinan.biondic@gmail.com</dc:creator><category>WebGrid</category><category>DataSource</category><category>Server-side</category><category>serverside</category><category>dynamically</category><category>column</category><category>remove</category><category>Unbound</category><category>DataBind</category><category>collection</category><category>datatable</category><category>PrepareDataBinding</category><category>aspx</category><category>server</category><category>side</category><description>&lt;p&gt;Hi Bernard,&lt;/p&gt;&lt;p&gt;thank you for your answer. This does work, sort of. I get all the columns that I have in my datasource. However, I have some columns that I don't want to show in the grid, so their width is set to 0px(I can't hide them with visible=false because I need their data), they have some data formating options defined also, and I'm defining all of that in aspx. So what i really want is to show only those columns contained in datasource, but with the options that I already defined in markup, and hide all the other columns. What I succeded to do is to check if column is not contained in datasource and just set it's Bound and Visible properties to false. With that all other columns defined in markup, and contained in datasource are binded and their properties are preserved as defined in aspx. I would want to know if there's a better option for doing this. If I do it as you suggested, then i still have to define all properties in PrepareDataBinding event.&lt;/p&gt;</description></item><item><title>Remove column defined in aspx markup, from server-side</title><link>http://www.intersoftsolutions.com/Community/WebGrid/Remove-column-defined-in-aspx-markup-from-server-side/</link><pubDate>Wed, 17 Apr 2013 01:45:57 GMT</pubDate><dc:creator>bernard</dc:creator><category>WebGrid</category><category>DataSource</category><category>Server-side</category><category>serverside</category><category>dynamically</category><category>column</category><category>remove</category><category>Unbound</category><category>DataBind</category><category>collection</category><category>datatable</category><category>PrepareDataBinding</category><category>aspx</category><category>server</category><category>side</category><description>&lt;p&gt;Hi Nikola,&lt;/p&gt;&lt;p&gt;Actually, you can get the structure of your DataTable and apply it on WebGrid in PrepareDataBinding event by using RetrieveStructure function. You can also remove the column that you don't want to show after retrieved the structure from your DataTable. With this method, you don't have to declare WebGridColumn inside WebGrid at the first time. I've made you a sample that using this scenario to apply the structure into WebGrid. I attach the sample here. Could you look for my sample and tell me if this sample achieve your scenario or no?&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Bernard&lt;/p&gt;</description></item><item><title>Remove column defined in aspx markup, from server-side</title><link>http://www.intersoftsolutions.com/Community/WebGrid/Remove-column-defined-in-aspx-markup-from-server-side/</link><pubDate>Tue, 16 Apr 2013 16:03:03 GMT</pubDate><dc:creator>sinan.biondic@gmail.com</dc:creator><category>WebGrid</category><category>DataSource</category><category>Server-side</category><category>serverside</category><category>dynamically</category><category>column</category><category>remove</category><category>Unbound</category><category>DataBind</category><category>collection</category><category>datatable</category><category>PrepareDataBinding</category><category>aspx</category><category>server</category><category>side</category><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I am trying to implement webgrid but the problem exists when I'm binding it to datasource. I have a stored procedure that returns some data.However, I don't know how many columns will be returned in that procedure, but I know the names of all columns that can be returned. So what I wanted to do, is to define all possible columns in aspx page, and in server-side PrepareDataBinding method remove columns from webgrid's column collection that don't have their match in datasource datatable that I'm binding it to.&lt;/p&gt;
&lt;p&gt;This doesn't really work as I get an error stating that columne "XYZ" which is defined in aspx can't be found in datasource, although it was removed (I checked with debugger) in PrepareDataBinding event handler.&lt;/p&gt;
&lt;p&gt;I presume this then is not possible, or am I wrong? The reason I am not creating columns from codebehind is simply that I would have to check datasource for every column to see if it exists and then create that column dynamically and add it to the column collection of webgrid. We did that in old version of our application and that PrepareDataBinding method has over 1600 lines of code, so I am looking for a better way of doing this. Please help me for the love of god!&lt;/p&gt;
&lt;p&gt;This is my PrepareDataBinding method (column named "Check" is rowchecker column so i don't want it removed):&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p /&gt;&lt;pre&gt;Dim dt As DataTable = CType(e.DataSource, DataTable)
 Dim grid As WebGrid = CType(sender, WebGrid)
 Dim colName As String
 For Each col As WebGridColumn In grid.RootTable.Columns
 colName = col.DataMember
 If Not colName = "Check" AndAlso Not dt.Columns.Contains(colName) Then
 grid.RootTable.Columns.Remove(col)
 End If
 Next&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p /&gt;
&lt;p /&gt;</description></item></channel></rss>