HOWTO: Using the bindAllColumns Method to Rebind a Grid DTC

ID: Q193226


The information in this article applies to:


SUMMARY

The bindAllColumns method is used to bind all the columns in the current recordset to a Grid Design-time control (DTC). This method is specifically useful when the number of columns in the underlying recordset of a bound Grid DTC changes or is not known at design time. In that case, the bindAllColumns method associated with the Grid DTC has to be called to rebind the Grid with the recordset so that the updated number of columns in the recordset can appear on the Grid.


MORE INFORMATION

This example shows a Grid DTC bound to a recordset that is set to the Customers table in the sample AdvWorks.mdb database. If a different database is used, modify the select statement in the sample code provided below to use a valid table from the database.

When the user clicks Button1, the ChangeRS function is called in the onclick event of Button1. The recordset is closed and the setSQLText of the recordset is changed. Then the Grid DTC is rebound to the new recordset using the bindAllColumns method.

Following are the step-by-step procedures:

  1. Open a new Web project in Visual InterDev 6.0 and a new Active Server Pages (ASP) page.


  2. Create a database connection to the sample AdvWorks.mdb database in the project.


  3. Add a Recordset DTC to the ASP page.


  4. Bind the recordset to a table in the data connection.


  5. Add a Grid DTC to the ASP page.


  6. Bind the Grid DTC to the recordset and select some fields.


  7. Add a Button DTC to the ASP page.


  8. Add the following code to the ASP page:
    
          <SCRIPT ID=serverEventHandlersVBS LANGUAGE=vbscript RUNAT=Server>
             Sub Button1_onclick()
                call ChangeRS
             End Sub
    
             Sub Grid_onenter()
                If thisPage.firstEntered then
                   Recordset1.open
                End if
             End Sub
    
             Sub ChangeRS()
                If Recordset1.isOpen() then Recordset1.close()
    
                'Change to a New SQL Statement
                Recordset1.setSQLText( "Select * from Employees")
                Recordset1.open
                Grid1.bindAllColumns
            End Sub
          </SCRIPT> 


  9. Click Button1 to rebind the grid.


Additional query words:


Keywords          : kbCtrl kbVisID600 kbGrpASP 
Version           : WINDOWS:6.0
Platform          : WINDOWS 
Issue type        : kbhowto 

Last Reviewed: May 27, 1999