Presentation is loading. Please wait.

Presentation is loading. Please wait.

ASP.NET Presented by Pan Gao. ASP.NET Next generation of ASP Next generation of ASP Program Language to build web application Program Language to build.

Similar presentations


Presentation on theme: "ASP.NET Presented by Pan Gao. ASP.NET Next generation of ASP Next generation of ASP Program Language to build web application Program Language to build."— Presentation transcript:

1 ASP.NET Presented by Pan Gao

2 ASP.NET Next generation of ASP Next generation of ASP Program Language to build web application Program Language to build web application Part of Microsoft.Net Platform Part of Microsoft.Net Platform ASP.net pages have a new file extension,.aspx ASP.net pages have a new file extension,.aspx Better Language support Better Language support Has a large set of new controls Has a large set of new controls Even – driven programming Even – driven programming XML based programming XML based programming

3 ASP.Net Key elements 1. Text Box Control 2. Radio Button List 3. Check box control 4. Form and Buttons 5. Event Control 6. HyperLink Control 7. Array 8. Binding 9. Hast Table 10. Data Set 11. Database Connection and Displaying

4 Define Text Boxes Control 1. 2. 3....................

5 Define Radio Button List Control Red Red Blue Blue Green Green

6 asp:CheckBox Control Click to Submit Click to Submit Submitted Submitted Sub CheckedBox (Src As Object, Args As EventArgs) MyCheckBox.Text = "Submitted" End Sub

7 Forms and Buttons Sub submit(Source As Object, e As EventArgs) button1.Text="You clicked me!" End Sub Sub submit(Source As Object, e As EventArgs) button1.Text="You clicked me!" End Sub

8 ASP.NET Event Control Sub Page_Load Sub Page_Load lbl1.Text="The date and time is " & now() lbl1.Text="The date and time is " & now() End Sub End Sub The date and time is 24.11.2003 06:36:21 The date and time is 24.11.2003 06:36:21

9 ASP.NET HyperLink Control Here is a text link to the Home Page Here is a text link to the Home Page Here is a text link to the Home Page Here is a text link to the Home Page

10 Array in ASP.NET Sub Page_Load If Not IsPostBack Then Dim ColorList = New ArrayList ColorList.Add("Red") ColorList.Add("Green") ColorList.Add("Blue") ColorList.TrimToSize() ColorList.Sort() End If End Sub Blue Green red

11 Binding to an ArrayList Dim ColorList As New ArrayList ColorList.Add("Red") ColorList.Add("Green") ColorList.Add("Blue") ColorList.TrimToSize() ColorList.Sort() RadioButtons.DataSource = ColorList RadioButtons.DataBind Dim ColorList As New ArrayList ColorList.Add("Red") ColorList.Add("Green") ColorList.Add("Blue") ColorList.TrimToSize() ColorList.Sort() RadioButtons.DataSource = ColorList RadioButtons.DataBind

12 ASP.NET Hash Table sub Page_Load sub Page_Load if Not Page.IsPostBack then if Not Page.IsPostBack then dim mycountries=New Hashtable dim mycountries=New Hashtable mycountries.Add("N","Norway") mycountries.Add("S","Sweden") mycountries.Add("F","France") mycountries.Add("I","Italy") rb.DataSource=mycountries rb.DataValueField="Key" rb.DataTextField="Value" rb.DataBind() mycountries.Add("N","Norway") mycountries.Add("S","Sweden") mycountries.Add("F","France") mycountries.Add("I","Italy") rb.DataSource=mycountries rb.DataValueField="Key" rb.DataTextField="Value" rb.DataBind() end if end if end sub end sub sub displayMessage(s as Object,e As EventArgs) sub displayMessage(s as Object,e As EventArgs) lbl1.text="Your favorite country is: " & rb.SelectedItem.Text lbl1.text="Your favorite country is: " & rb.SelectedItem.Text end sub end sub

13 France France Sweden Sweden Italy Italy Norway Norway Your favorite country is: Italy France France Sweden Sweden Italy Italy Norway Norway Your favorite country is: Norway

14 XML Files and DataSet - - - - - - Norway Norway N N - - - Sweden Sweden S S - - - France France F F - - - Italy Italy I I

15 Dataset Sub Page_Load If Not IsPostBack Then Dim MenuItems = New DataSet MenuItems.ReadXml(MapPath(“test.xml")) End If End Sub Sub Page_Load If Not IsPostBack Then Dim MenuItems = New DataSet MenuItems.ReadXml(MapPath(“test.xml")) End If End Sub

16 Binding to control sub Page_Load if Not Page.IsPostBack then dim mycountries=New DataSet mycountries.ReadXml(MapPath("countries.xml")) rb.DataSource=mycountries rb.DataValueField="value" rb.DataTextField="text" rb.DataBind() end if end sub sub displayMessage(s as Object,e As EventArgs) lbl1.text="Your favorite country is: " & rb.SelectedItem.Text end sub sub Page_Load if Not Page.IsPostBack then dim mycountries=New DataSet mycountries.ReadXml(MapPath("countries.xml")) rb.DataSource=mycountries rb.DataValueField="value" rb.DataTextField="text" rb.DataBind() end if end sub sub displayMessage(s as Object,e As EventArgs) lbl1.text="Your favorite country is: " & rb.SelectedItem.Text end sub

17 Binding to a control

18 Displaying France Sweden Italy Norway Your Favorite country is: Norway

19 ASP.NET Database Connection OleDbConnection - for connecting to a database OleDbConnection - for connecting to a database OleDbCommand - for issuing SQL queries against database tables OleDbCommand - for issuing SQL queries against database tables OleDbDataReader - for access to the datasets retrieved from queries OleDbDataReader - for access to the datasets retrieved from queries

20 Opening a Database Connection Sub Page_Load 'Open database connection Sub Page_Load 'Open database connection Dim DBConnection = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0; Dim DBConnection = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0; DATA SOURCE=d:\Databases\eCommerce.mdb") DBConnection.Open() End Sub DATA SOURCE=d:\Databases\eCommerce.mdb") DBConnection.Open() End Sub

21 Creating a Database Command Sub Page_Load 'Open database connection Sub Page_Load 'Open database connection Dim DBConnection = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0; DATA SOURCE=d:\Databases\eCommerce.mdb") DBConnection.Open() 'Create database command and issue through connection Dim DBConnection = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0; DATA SOURCE=d:\Databases\eCommerce.mdb") DBConnection.Open() 'Create database command and issue through connection Dim SQLString = "SELECT * FROM Products" Dim DBCommand = New OleDbCommand(SQLString, DBConnection) End Sub Dim SQLString = "SELECT * FROM Products" Dim DBCommand = New OleDbCommand(SQLString, DBConnection) End Sub

22 Creating a DataReader Sub Page_Load 'Open database connection Dim DBConnection = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0; DATA SOURCE=d:\Databases\eCommerce.mdb") DBConnection.Open() 'Create database command and issue through connection Dim SQLString = "SELECT * FROM Products" Dim DBCommand = New OleDbCommand(SQLString, DBConnection) 'Return dataset to data reader Dim DBReader = DBCommand.ExecuteReader() End Sub Sub Page_Load 'Open database connection Dim DBConnection = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0; DATA SOURCE=d:\Databases\eCommerce.mdb") DBConnection.Open() 'Create database command and issue through connection Dim SQLString = "SELECT * FROM Products" Dim DBCommand = New OleDbCommand(SQLString, DBConnection) 'Return dataset to data reader Dim DBReader = DBCommand.ExecuteReader() End Sub

23 Display Database Records sub Page_Load dim dbconn,sql,dbcomm,dbread sub Page_Load dim dbconn,sql,dbcomm,dbread dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & server.mappath("northwind.mdb")) dbconn.Open() dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & server.mappath("northwind.mdb")) dbconn.Open() sql="SELECT * FROM customers" dbcomm=New OleDbCommand(sql,dbconn) dbread=dbcomm.ExecuteReader() sql="SELECT * FROM customers" dbcomm=New OleDbCommand(sql,dbconn) dbread=dbcomm.ExecuteReader() customers.DataSource=dbread customers.DataBind() customers.DataSource=dbread customers.DataBind() dbread.Close() dbconn.Close() end sub dbread.Close() dbconn.Close() end sub

24 Display Database Companyname Contactname Address City Companyname Contactname Address City

25 Display Database Companyna me Contactna me AddressCity Big boy Sam 13 th street LA Big girls Mary 14 th street Boston Big pigs John 15 th street NY


Download ppt "ASP.NET Presented by Pan Gao. ASP.NET Next generation of ASP Next generation of ASP Program Language to build web application Program Language to build."

Similar presentations


Ads by Google