Hi guys,
I'm an .NET newbie, I need help.
Why is it that when I preview my aspx page it won't show up anything except this line:
<p>The data will be refreshed 10 seconds from now: <%= DateTime.Now %></p>
Here's my code below:
thanks. -tj
I'm an .NET newbie, I need help.
Why is it that when I preview my aspx page it won't show up anything except this line:
<p>The data will be refreshed 10 seconds from now: <%= DateTime.Now %></p>
Here's my code below:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ OutputCache Duration="10" VaryByParam="None" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Data" %>
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Page Data Caching</title>
<script type="text/c#" language="C#" runat="server">
DataView objDV;
void Page_Load() {
if (IsPostBack) {
dgEmployees.DataSource = GetEmployees();
dgEmployees.DataBind();
}
}
DataView GetEmployees() {
DataSet objDS = new DataSet();
OleDbConnection objConn = new OleDbConnection(ConfigurationSettings.AppSettings["DNS"]);
OleDbDataAdapter objDA;
objDV = (DataView)Cache["Employees"];
if (objDV == null) {
objDA = new OleDbDataAdapter("SELECT * FROM Employees", objConn);
objDA.Fill(objDS, "Employees");
objDV = objDS.Tables["Employees"].DefaultView;
Cache["Employees"] = objDV;
}
return objDV;
}
void dgEmployees_Sort(Object s, DataGridSortCommandEventArgs e) {
objDV = GetEmployees();
objDV.Sort = e.SortExpression;
dgEmployees.DataSource = objDV;
dgEmployees.DataBind();
}
</script>
</head>
<body>
<form runat="server">
<asp:DataGrid ID="dgEmployees" runat="server" AutoGenerateColumns="false" GridLines="None" AllowSorting="true" OnSortCommand="dgEmployees_Sort">
<ItemStyle Font-Names="Arial" Font-Size="10pt" ForeColor="#000000" />
<HeaderStyle Font-Names="Arial" Font-Size="10pt" ForeColor="#FFFFFF" Font-Bold="true" BackColor="#003366" />
<AlternatingItemStyle Font-Names="Arial" Font-Size="10pt" BackColor="#CCCCCC" />
<Columns>
<asp:BoundColumn DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundColumn DataField="Extension" HeaderText="Extension" SortExpression="Extension" />
</Columns>
</asp:DataGrid>
<p>The data will be refreshed 10 seconds from now: <%= DateTime.Now %></p>
</form>
</body>
</html>
Comment