J
jonefer
I found this code in ASP.NET forum
It's the first code that actually built the grid the way I wanted with the
sortfields on only certain columns
However... the columns don't get rebuilt between searches
so it errors out - when there is a result set with less columns
I thought that was the reason for the dynamic bound columns
How can I make sure that it starts fresh everytime the search button is
clicked?
For Each dc As DataColumn In ds.Tables(0).Columns
Dim bField As BoundField = New BoundField
'Initalize the DataField value.
bField.DataField = dc.ColumnName
'Initialize the HeaderText field value.
bField.HeaderText = dc.ColumnName
If Left(dc.ColumnName, 14) = "General Course" Then
bField.SortExpression = dc.ColumnName
End If
'Add the newly created bound field to the GridView.
gvActionList.Columns.Add(bField)
Next
'=======================================
gvActionList.DataSource = ds
gvActionList.DataBind()
ShowGrid(True)
Me.lblCheck.Text = ""
It's the first code that actually built the grid the way I wanted with the
sortfields on only certain columns
However... the columns don't get rebuilt between searches
so it errors out - when there is a result set with less columns
I thought that was the reason for the dynamic bound columns
How can I make sure that it starts fresh everytime the search button is
clicked?
For Each dc As DataColumn In ds.Tables(0).Columns
Dim bField As BoundField = New BoundField
'Initalize the DataField value.
bField.DataField = dc.ColumnName
'Initialize the HeaderText field value.
bField.HeaderText = dc.ColumnName
If Left(dc.ColumnName, 14) = "General Course" Then
bField.SortExpression = dc.ColumnName
End If
'Add the newly created bound field to the GridView.
gvActionList.Columns.Add(bField)
Next
'=======================================
gvActionList.DataSource = ds
gvActionList.DataBind()
ShowGrid(True)
Me.lblCheck.Text = ""