Dynamically boundfields aren't really dynamic

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 = ""
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top