Almost right...
ASP.NET is code that generates HTML based on something, usually the results of an SQL Query. in ASP.NET, your connection string would go in a global config file so it could be used from any page.
Imagine an ASP.NET page as like a template - most of it is in HTML, however you put ASP.NET controls within the HTML. For example:
Code:
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default" %>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Rocket 3G League Table</title>
<metahttp-equiv="refresh"content="30"/>
<styletype="text/css">
@import url( Default.css );
</style>
</head>
<body>
<formid="frmMain"runat="server">
<div>
<divid="Title">
<h1>Rocket 3G Leaguetable</h1>
</div>
<divstyle="padding: 10px;">
<asp:DataGridID="dgData"runat="server"AutoGenerateColumns="false"Width="100%"ShowFooter="true"OnItemDataBound="dgData_ItemDataBound"Font-Size="Large"BorderWidth="0"CellSpacing="1">
<HeaderStyleHorizontalAlign="Center"Font-Bold="true"BackColor="#FF6600"/>
<ItemStyleHorizontalAlign="Center"BackColor="#FFFF99"/>
<FooterStyleHorizontalAlign="Center"Font-Size="Large"BackColor="#999999"Font-Bold="true"/>
<Columns>
<asp:BoundColumnHeaderText="Agent Name"DataField="Name"ItemStyle-HorizontalAlign="Left"HeaderStyle-HorizontalAlign="Left"FooterText="Total"FooterStyle-HorizontalAlign="Left"/>
<asp:BoundColumnHeaderText="Calls<br />Today"DataField="Calls"ItemStyle-Width="110px"/>
<asp:BoundColumnHeaderText="Daily<br />Sales"DataField="DailySales"ItemStyle-Width="110px"/>
<asp:BoundColumnHeaderText="Monthly<br />Sales"DataField="Sales"ItemStyle-Width="110px"/>
<asp:BoundColumnHeaderText="Monthly<br />Connections"DataField="Connections"ItemStyle-Width="110px"/>
<asp:BoundColumnHeaderText="Points"DataField="Points"ItemStyle-Width="110px"/>
</Columns>
</asp:DataGrid>
</div>
<divstyle="text-align: center;">
<asp:ImageID="imgScoreboard"runat="server"AlternateText="Scoreboard"/>
</div>
</div>
</form>
</body>
</html>
That's the page I'm working on at the moment. It's mostly plain HTML, but the tags prefixed with asp: are 'Server Controls' - the asp:DataGrid will be rendered as an HTML Table of Data, and the asp:Image will be rendered as an html <img ... /> tag.
Now all I need to do is get the data from the SQL Database and merge it with that asp:DataGrid (that's known as 'Data Binding'. ASP.NET will take the data and format it into an HTML Table based on all the settings in the <asp:DataGrid> control.
Code:
SqlConnection MyConnection = newSqlConnection(ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString);
SqlCommand MyCommand = newSqlCommand("SELECT * FROM LeagueData", MyConnection);
MyConnection.Open();
try
{
SqlDataReader MyReader = MyCommand.ExecuteReader();
dgData.DataSource = MyReader;
dgData.DataBind();
}
finally
{
MyConnection.Close();
}
There's loads of other controls you can use for different things, and practicly any aspect of the HTML page can be controlled from the code. The code above is in C#, but you can also do it in VisualBasic.NET, J#, or any other .NET language.
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"
Please login or register to view this content. Registration is FREE | Please login or register to view this content. Registration is FREE
Last edited by Minaki; 04-07-2006 at 07:27 AM..
|