Dynamically boundfields aren't really dynamic

Discussion in 'ASP .Net Building Controls' started by jonefer, May 23, 2007.

  1. jonefer

    jonefer Guest

    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 = ""
     
    jonefer, May 23, 2007
    #1
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.