An Introduction To ASP.NET
K. Yue, copyright 2001
Created April 3, 2001
Introduction
Advantages of ASP.NET
Simple Examples
Example: datagrid
<%@ language="vb" %>
<%@ import namespace="system.data" %>
<%@ import namespace="system.data.ado" %>
<script language="vb" runat="server">
dim cnn as adoconnection
dim cmd as adodatasetcommand
dim ds as new dataset
public sub page_load(sender as object,e as eventargs)
if page.ispostback=false then
cnn=new adoconnection("dsn=mydsn")
cmd=new adodatasetcommand("select
* from sometable",cnn)
cmd.filldataset(ds,"result")
resultgrid.datasource=ds.tables("result").defaultview
resultgrid.databind()
end if
end sub
</script>
<form id=form1 runat="server">
<asp:datagrid id="resultgrid" runat="server"
font-name="Verdana"
font-size="10pt"
BorderColor="black"
CellPadding="3"
headerstyle-backcolor="gray"
headerstyle-forecolor="black"
alternatingitemstyle-backcolor="silver"
itemstyle-backcolor="#ccccff"/>
</form>
Notes:
Example:
drawing.asp
<%@ Page Language="C#" Debug="true" %>
<!-- by K. Yue April 5, 2001 -->
<html>
<script language="C#" runat=server>
private void btnclick_click(object sender, EventArgs e) {
int i = 0;
i = int.Parse(txtRed.Text);
i = i * 256 + int.Parse(txtGreen.Text);
i = i * 256 + int.Parse(txtBlue.Text);
lblcolor.BackColor = System.Drawing.Color.FromARGB(i);
}
</script>
<body>
<form action="drawing.aspx" method="post"
runat="server">
<asp:Label runat="server" id="lblcolor"
Text="CSCI 4230 Internet Application Development"/>
<br><br>
Red (0 to 255):
<asp:TextBox id="txtRed" Text="0" Width="3em"
runat="server"/>
<asp:RangeValidator id="redVal" Type="Integer"
ControlToValidate="txtRed"
MaximumValue="255" MinimumValue="0" runat="server"
ErrorMessage="Number must be 0 to 255!" runat="server"/>
<br>
Green (0 to 255):
<asp:TextBox id="txtGreen" Text="0" Width="3em"
runat="server"/>
<asp:RangeValidator id="greemVal" Type="Integer"
ControlToValidate="txtGreen"
MaximumValue="255" MinimumValue="0" runat="server"
ErrorMessage="Number must be 0 to 255!" runat="server"/><br>
Blue (0 to 255):
<asp:TextBox id="txtBlue" Text="0" Width="3em"
runat="server"/>
<asp:RangeValidator id="blueVal" Type="Integer"
ControlToValidate="txtBlue"
MaximumValue="255" MinimumValue="0" runat="server"
ErrorMessage="Number must be 0 to 255!" runat="server"/>
<br><br>
<asp:Button Text="Click Here" id="btnClick"
onClick="btnclick_click" Runat=server />
<br>
</form>
</body>
</html>