Friday, June 8, 2007

Simple ASPX Output from a Database

Here is something that seemed hard to find on the internet when I was trying to create some simple output out of .NET directly to javascript. This simple sample I came up with to remind me of how to do it for the future and maybe it can help you as well. All you would need to do is setup a database and change the script below to reference your instance of SQL Express.


<html xmlns="http://www.w3.org/1999/xhtml" >
<head
runat="server">
<title>Simple Output
Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:Repeater ID="repeater1" runat="server"
DataSourceID="SqlDataSource1">
<ItemTemplate>
<%# Eval("TimeText") %><br />
</ItemTemplate>
</asp:Repeater>


<asp:SqlDataSource ID="SqlDataSource1" runat="server"
connectionString="Data Source=(YOUR_DATABASE_SERVER)\SQLEXPRESS;Initial
Catalog=(YOUR_DATABASE);Integrated Security=True;Pooling=False"
providerName="System.Data.SqlClient"
SelectCommand="SELECT
[TimeText],[TimeOrder] FROM [(YOUR_TABLE)] ORDER BY [TimeOrder]">
</asp:SqlDataSource>

</div>
</form>
</body>
</html>