HOWTO: Format Data in a Visual InterDev 6.0 Grid Design-Time Control

ID: Q243515


The information in this article applies to:
  • Microsoft Visual InterDev, version 6.0


SUMMARY

Using the Visual InterDev 6.0 Grid Design-Time Control (DTC), you can easily develop professional looking Web pages to present your information from your database. Often, however, the data that you present needs to be formatted differently than its format in the database. For instance, a date field may come from the database in the form of mm/dd/yy, but you want it to be displayed as mm/dd/yyyy.


MORE INFORMATION

By using the field/expression field of the Grid DTC, you can call custom built Active Server Pages (ASP) functions to format and then return data back to the grid to be displayed.

Before You Begin


This sample uses the Northwind database. Before you begin, open a Visual InterDev 6.0 project with a Data Connection to the Northwind database, which is called "nwind." The Northwind database can be installed as an option with Microsoft Access or Microsoft Visual Basic and can be found at Program Files\Microsoft Office\Office\Samples\Northwind.mdb or Program Files\Microsoft Visual Studio\VB98\Nwind.mdb, respectively.

Step 1: Create the ASP page and add the Design-Time Controls

  1. Add an ASP page to your project.


  2. To add a Recordset DTC, click the View menu, select Toolbox, and select Design-Time Controls. Drag a Recordset DTC onto the ASP page in the <BODY> section.


  3. If prompted to enable the Scripting Object Model for this page, click Yes.


  4. Add a Grid DTC to the <BODY> section after the Recordset DTC.


Step 2: Set the Properties of the Recordset DTC

  1. Select the Recordset DTC (Recordset1).


  2. Set the Connection property to nwind (see "Before You Begin" earlier in this article), the Database Object property to Tables, and the Object Name property to Orders.


Step 3: Set the Properties of the Grid DTC

  1. Right-click the Grid DTC (Grid1) and select Properties.


  2. In the General tab, set the Style Name to Insert Gray, change the Width from Pixels to Percentage, and set the size to 100.


  3. Select the Navigation tab and set the records/page property to 10.


  4. Select the Data tab, and set the Recordset property to Recordset1.


  5. In the Available Fields window, select CustomerID, OrderDate, ShippedDate.

    OrderDate
    The OrderDate field needs to call a function that converts the date retrieved from the database and return it formatted with a four-digit year.

    1. In the Grid Columns dialog box, select OrderDate.


    2. Change the Field/Expression value to the following:


    3. 
      =convertDate([OrderDate]) 
    4. Click Update.


    ShippedDate
    The ShippedDate field needs to call a function that will convert the date retrieved from the database and return it formatted with a 4 digit year.

    1. In the Grid Columns dialog box, select ShippedDate.


    2. Change the Field/Expression value to the following:


    3. 
      =convertDate([ShippedDate]) 
    4. Click Update.




  6. Click OK to close the Properties page of the Grid DTC.


Step 4: Write the Code That Does the Conversion

In the <HEAD> section of the page, place the following code that is referenced by the Grid DTC:

<%
Function convertDate(txtdate)

if txtDate = ""  then
convertDate = ""
else
dteDay = Day(txtDate)
dteMonth = Month(txtDate)
dteYear = Year(txtDate)

convertDate = dteMonth & "/" & dteDay & "/" & dteYear
End if

End Function
%> 

Additional query words:

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


Last Reviewed: December 10, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.