Hi all,
I've been stuck for a while trying to setup our WHDG. We have a dynamic, changing, dataset object coming back from our databases. This can have N relationships and tables in it. We must create the bands manually so that we can hide columns and format the display.
Note: If I set the grid to auto create the bands, it works fine but the display is no good for our needs.
However, if I try to create a band for each dataTable in the set then the 2nd level + band I create are not used.
Also, if I create the bands manually but leave AutoGenerateBands="True" then the 2nd level band has no formatting.
Is there some way I can view the auto generated bands in code? If so then maybe I could see what was wrong with my setup.
This is the function I used to setup the bands:
Protected Overrides Sub OnInit(ByVal e As EventArgs)
Dim i As Integer = 1 ' skip root band/table (this is already setup in the grid)
While i < Me.WHDG1.DataSource.Tables.Count
Dim band As New Infragistics.Web.UI.GridControls.Band
Dim table As New DataTable
table = Me.WHDG1.DataSource.Tables(i)
Me.WHDG1.Bands.Add(band)
band.DataMember = table.TableName
band.Key = table.TableName
band.DataKeyFields = "Autoid"
band.ShowHeader = False
band.AutoGenerateColumns = False
addDataField("Sel", "Sel", "20", False, "columnClassSel", table, band)
addDataField("Sel1", "Sel", "20", False, "columnClassSel", table, band)
addDataField("Sel2", "Sel", "20", False, "columnClassSel", table, band)
addDataField("Sel3", "Sel", "20", False, "columnClassSel", table, band)
addDataField("Sel4", "Sel", "20", False, "columnClassSel", table, band)
addDataField("Sel5", "Sel", "20", False, "columnClassSel", table, band)
addDataField("Sel6", "Sel", "20", False, "columnClassSel", table, band)
addDataField("display", "display", "", False, "", table, band)
addDataField("Available", "Available", "70", False, "columnClassAvailable", table, band)
addDataField("name", "name", "", True, "", table, band)
addDataField("parenttable", "parenttable", "", True, "", table, band)
addDataField("parentkey", "parentkey", "", True, "", table, band)
addDataField("childtable", "childtable", "", True, "", table, band)
addDataField("level", "level", "", True, "", table, band)
addDataField("filter", "filter", "", True, "", table, band)
addDataField("incex", "incex", "", True, "", table, band)
addDataField("tbl", "tbl", "", True, "", table, band)
addDataField("bandkey", "bandkey", "", True, "", table, band)
i = i + 1
End While
Private Sub addDataField(ByVal fieldName As String, ByVal key As String, ByVal width As String, ByVal hidden As Boolean, ByVal cssClass As String, ByRef table As DataTable, ByRef band As Infragistics.Web.UI.GridControls.Band)
If table.Columns.Contains(fieldName) Then
Dim dataField As Infragistics.Web.UI.GridControls.BoundDataField = New Infragistics.Web.UI.GridControls.BoundDataField
dataField.DataFieldName = fieldName
dataField.Key = fieldName
dataField.Hidden = hidden
dataField.CssClass = cssClass
If Not width = "" Then
dataField.Width = width
End If
band.Columns.Add(dataField)
End Sub
Hello,
How would you create the following columns through the code-behind class?
<ig:BoundDataField DataFieldName="ID" Key="ID" Header-Text="ID" /> <ig:BoundDataField DataFieldName="Fname" Key="Fname" Header-Text="First Name" Width="230px" /> <ig:BoundDataField DataFieldName="Sname" Key="Sname" Header-Text="Second Name" Width="150px" />
I've tried to add the following to your sample:
private void AddBandColumn(IBand band, string dataField, string caption, bool hidden) //, AllowUpdate updatable) { BoundDataField column = new BoundDataField(true); column.DataFieldName = dataField; column.Key = dataField; column.Hidden = hidden; column.Header.Text = caption; band.Columns.Add(column); }
private void CreateColumns() { this.whdg1.Bands.Clear(); this.whdg1.Columns.Clear();
this.whdg1.DataKeyFields = "ID";
AddBandColumn(this.whdg1, "ID", "ID", false); AddBandColumn(this.whdg1, "Fname", "First Name", false); AddBandColumn(this.whdg1, "Sname", "Second Name", false);
//Second Level - Child Band band = new Band(); AddBandColumn(band, "ID", "ID", false); AddBandColumn(band, "City", "City", false); AddBandColumn(band, "Street", "Street", false); this.whdg1.GridView.Bands.Add(band); }
I even tried adding the parent columns to this.whdg1.GridView.Columns, but did not work.
Thanks
I also wanted to add that this feels like bad practice to be setting column properties in the InitializeRow event. It seems like there should be a better place to be doing this in order to not have it called thousands of times with each of my rows.
Hi Rado,
I couldn't get the approach to work with my code, so I decided to take baby steps. If I take your exact example, it runs as expected. I then replace the call to GetPersons with my own call to retrieve my datatable (confirmed that the datatable is returned) and then replaced the bound columns with bound columns that match my datatable. No other code changes. I then get this error which really doesn't tell me anything. Any ideas?
Thanks,
Tami
InvalidOperationException] Infragistics.Web.UI.GridControls.WebHierarchicalDataGrid.DataBind() +1082 Infragistics.Web.UI.GridControls.WebHierarchicalDataGrid.EnsureDataBound() +70 System.Web.UI.WebControls.BaseDataBoundControl.OnPreRender(EventArgs e) +22 Infragistics.Web.UI.Framework.Data.HierarchicalDataBoundControlMain.OnPreRender(EventArgs e) +196 Infragistics.Web.UI.GridControls.WebHierarchicalDataGrid.OnPreRender(EventArgs e) +37 System.Web.UI.Control.PreRenderRecursiveInternal() +80 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842
Thanks for the suggestion, I will work on changing my code to the suggestion. I also need to be able to control the columns of the parent band on load though and your example is only for children. The problem is that my parent band will have a varying number of columns, so I can't define my bound columns in the html. Any suggestions?
Hi pwerey,
Thanks for the sample. I see the behavior. This is an issue with the control which exists in the RTM version. The good news is that it was resolved and you could take advantage of the fix with the latest service release, just download it and upgrade.
Hope this helps.