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 know how to manually add a column via code behind to the grid roottable, but when I do the actual databind all the columns show up inthe grid. I only want to paint a certain number of them. I only want the columns I'm adding the grid from the BuildColumns() function below, but it binds all rows coming back form the GetGridData. For example, the dataset returns back first name, last name and ssn. I just want to display last name in the grid but want to bind it to the dataset. What's the best way to accomplish this? Is it a timing issue I'm hitting? Any help would be greatly appreciated!
BuildColumns()
SetGridProperties()
BindGridData()
Private Sub BuildColumns()
newGC.AllowSorting = Sorting.Yes
Grid.RootTable.Columns.Add(newGC)
GridView.DataSource = GetGridData()
GridView.DataBind()
In the simple sample as shown below, the grouping works.
Protected Sub WebGrid1_PrepareDataBinding(ByVal sender As Object, ByVal e As ISNet.WebUI.WebGrid.DataSourceEventArgs) Dim ColumnSet As String = "" ' make sure the codes only executed on page postback, but not an OnTheFly postback. If IsPostBack AndAlso (Not WebGrid1.IsFlyPostBack) Then If clickFlag = 1 OrElse clickFlag = 2 Then If clickFlag = 1 Then ColumnSet = ("CustomerID,CompanyName,ContactName,ContactTitle") Else ColumnSet = ("CustomerID,Country,Region,PostalCode") End If ' clear all columns before repopulated WebGrid1.RootTable.Columns.Clear() WebGrid1.RootTable.SortedColumns.Clear() WebGrid1.RootTable.GroupedColumns.Clear() Dim Columns As String() = ColumnSet.Split(","c) For Each Column As String In Columns Dim col As WebGridColumn = New WebGridColumn() col.DataMember = Column col.Caption = Column WebGrid1.RootTable.Columns.Add(col) Next Column ElseIf clickFlag = 3 Then WebGrid1.RootTable.SortedColumns.Clear() WebGrid1.RootTable.GroupedColumns.Clear() WebGrid1.RetrieveStructure() Dim groupByCountry As WebGridGroup = New WebGridGroup() groupByCountry.ColumnMember = "Country" groupByCountry.GroupInterval = GroupInterval.Default groupByCountry.SortOrder = SortOrder.Ascending WebGrid1.RootTable.GroupedColumns.Add(groupByCountry) End If End If End Sub
There should be no timing issue when using this sample since every single event is invoked synchronously.
I can’t have your sent sample run on my end because it uses some methods, classes, object, etc that is not available within the sample. If the issue is replicable in a running simple sample it will be so much helpful to be investigated further. If necessary, you may modify my sent sample so it replicates your issue and then have the sample sent back to us to be analyzed.
Thank you and look forward for your response.
I enclosed one simple sample of WebGrid that shows how to bind WebGrid manually and display different column via code behind.
I suggest you to do data source initialization in InitializeDataSource event and column structure retrieval in PrepareDataBinding event. The advantage of following this style is to utilize the advantages of WebGrid component extensively such as data caching feature is enabled if the assignment of WebGrid data source is placed in InitializeDataSource event.
WebGrid_InitializeDataSource eventAll codes related to the assignment of data source to the WebGrid component should be placed here. Codes that related to the DataTable structure creation, DataSet populating process with the DataAdapter and so many data related task could be processed here. In the conclusion, only data populating related codes should be placed here, no process of assigning WebGrid layout should be placed as depicted from the event name (InitializeDataSource).
WebGrid_PrepareDataBinding eventIn this event, developers can conveniently populate all the columns structure. When the InitializeDataSource event is invoked and the codes inside the InitializeDataSource event are executed, WebGrid will proceed to invoke the PrepareDataBinding event automatically.
WebGrid_InitializeLayout eventInitializeLayout event is originally designed to let developers programmatically configure static WebGrid’s behavior, appearance, look and feel, style, etc.
For more detail information about the event sequence of server side event in WebGrid, please check WebGrid documentation. Hope this helps.
Thanks. That worked! I actually had to declare the functions in the aspx code the intialize and databinding code. I tried just to use the default functions in the code behind for the grid and some how that didn't work. Now, my dynamic grouping does not work, but I should be able to resolve that. It gives an object reference not found error. I tried placing it in the WebGrid1_PrepareDataBinding event and also the WebGrid1_InitializeLayout to no avail. I know the column exists. Here's the error and code:
Error: Object reference not set to an instance of an object.
.Columns.Clear()
.SortedColumns.Clear()
reportGrid.RootTable.Columns.Add(col)
groupBy.ColumnMember = "vchHHName"
groupBy.GroupInterval = GroupInterval.Text
groupBy.SortOrder = SortOrder.Ascending
reportGrid.RootTable.GroupedColumns.Add(groupBy) ''it errors due to this line
End Sub
I was unable to repro your issue using the sample I attach on my previous post.
I made a minor modification to the sample I sent you before in order to add WebGrid GroupedColumn in PrepareDataBinding event. Below is the snippet of the changes.
The grouped columns works fine and no problem persist. If you still have the issue, could you please modify the sample I sent you (so that it replicates your issue) and then have the sample sent back to us for further investigation?
Hope this helps.
I implmented the same code except for a few differences. I try to perform the groupby without first clicking on a button. I don't need to run the RetrieveStructure function. If I add the column to the ascx side under the <roottable> <columns> section like below it works. But I don't know the column names so I can't do that. Once I remove the WebGridColumn from below it gives me the error assuming oI'm doing my grouping on the vchHHName. If I try to do my grouping on any other column that I don't include below it fails.
GroupedColumns can only be added on an existing column in WebGrid structure. If the column is not exist, then it will shows the error you get, “Object reference not set to an instance of an object.”.
Please ensure that the “GetReportsColumns()” method return “vchHHName” column.
Hi - It is one of the columns. I tried with a few others as well to no avail. Could it be a timing issue with when the grid builds out the columns from the GetReportColumns() and the creation of the groupby column? If I add it to the .ascx instead of dynamically adding it, it works.
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