Microsoft KB Archive/243515

= How To Format Data in a Visual InterDev 6.0 Grid Design-Time Control =

Article ID: 243515

Article Last Modified on 7/1/2004

-

APPLIES TO


 * Microsoft Visual InterDev 6.0 Standard Edition

-



This article was previously published under Q243515



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  section.
 * 3) If prompted to enable the Scripting Object Model for this page, click Yes.
 * 4) Add a Grid DTC to the  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
 Right-click the Grid DTC (Grid1) and select Properties. In the General tab, set the Style Name to Insert Gray, change the Width from Pixels to Percentage, and set the size to 100. Select the Navigation tab and set the records/page property to 10. Select the Data tab, and set the Recordset property to Recordset1. 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.

 In the Grid Columns dialog box, select OrderDate.</li>  Change the Field/Expression value to the following: =convertDate([OrderDate]) </li> Click Update.</li></ol>

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.

<ol style="list-style-type: lower-alpha;"> In the Grid Columns dialog box, select ShippedDate.</li>  Change the Field/Expression value to the following: =convertDate([ShippedDate]) </li> Click Update.</li></ol> </li> Click OK to close the Properties page of the Grid DTC.</li></ol>

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 %>

In a similar way, you could use this function for price fields that need to be formatted as currency: <%  Function convertCurrency(txtCurr)

If txtCurr="" then convertCurrency="$ 0.00" else convertCurrency = FormatCurrency(txtCurr) End If

End Function

Keywords: kbhowto kbctrl KB243515

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.