Displaying data from external database |
Beside displaying Kentico CMS content, you can also display data from your external databases or Web Service. In this case, you need to add custom code to your ASPX page that will use ADO.NET to retrieve the data or that will contact the Web Service and call its methods. Since you can place any custom code into the page (page template), you will simply use the standard ASP.NET code you would use if you created the web site from scratch.
Example: Retrieving data from the sample Northwind database
In this simple example, you will see how to display data from the Categories table of the Northwind database using ADO.NET, in the sample Corporate Site ASPX web site. You may need to use some other database if you do not have the sample database Northwind on your server.
Open the web project in Visual Studio 2005 using the WebProject.sln file. Open the page CMSTemplates\CorporateSiteASPX\home.aspx.
Drag and drop the standard ASP.NET GridView control on your user control and set its ID to GridView1.
Add the following line to the beginning of the code:
[C#]
Add the following code to the Page_Load method:
[C#]
Save all changes. See the page on the live web site. You will see a grid with data from the external database:
As you can see we used standard ASP.NET methods to display external data on the web site. |