"> ">

Presentation is loading. Please wait.

Presentation is loading. Please wait.

ASP and HTML. Anchor Tag testAnchorTag Demo: ASPNet/ASPNETProdListSelf.ASPX.

Similar presentations


Presentation on theme: "ASP and HTML. Anchor Tag testAnchorTag Demo: ASPNet/ASPNETProdListSelf.ASPX."— Presentation transcript:

1 ASP and HTML

2 Anchor Tag testAnchorTag Demo: ASPNet/ASPNETProdListSelf.ASPX

3 Creating Links Click a link to view a product: <% dim strConn as string ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:\sales2k.mdb" dim objConn as new OledbConnection(strConn) dim strSQL as string = "select * from product;" Dim objComm As New OleDbCommand(strSQL, objConn) objConn.Open() Dim objDataReader As OleDbDataReader objDataReader = objComm.ExecuteReader() Do While objDataReader.Read() = True response.write (" " & objDataReader("description") & " ") loop %>

4 Program that Response to links <% dim strConn as string ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:\sales2k.mdb" dim objConn as new OledbConnection(strConn) dim strSQL as string = "select * from product where pid = '" dim ProdID as String ProdID=Request.QueryString("pid") strSQL=strSQL & ProdID & "';" Dim objComm As New OleDbCommand(strSQL, objConn) objConn.Open() Dim objDataReader As OleDbDataReader objDataReader = objComm.ExecuteReader() objDataReader.Read response.write ("PID = " & objDataReader("pid") & " ") response.write ("Descrition = " & objDataReader("description") & " ") response.write ("Price = " & objDataReader("price")) %> Qty:

5 Links that Reference Itself Click a link to view a product: <% dim strConn as string ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:\sales2k.mdb" dim objConn as new OledbConnection(strConn) dim strSQL as string = "select * from product;" Dim objComm As New OleDbCommand(strSQL, objConn) objConn.Open() Dim objDataReader As OleDbDataReader objDataReader = objComm.ExecuteReader() Do While objDataReader.Read() = True response.write (" " & objDataReader("description") & " ") loop %> Note: The anchor tag will load the referenced page, but does not trigger Post Back.

6 Code in the Same Page Response to Link sub Page_Load() dim ProdID as String ProdID=Request.QueryString("pid") if Not ProdID="" Then dim strConn as string ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:\sales2k.mdb" dim objConn as new OledbConnection(strConn) dim strSQL as string = "select * from product where pid = '" strSQL=strSQL & ProdID & "';" Dim objComm As New OleDbCommand(strSQL, objConn) objConn.Open() Dim objDataReader As OleDbDataReader objDataReader = objComm.ExecuteReader() objDataReader.Read response.write ("PID = " & objDataReader("pid") & " ") response.write ("Descrition = " & objDataReader("description") & " ") response.write ("Price = " & objDataReader("price")) end if end sub

7 Creating Forms Creating a form for each product in the product table. Demo: ASPNet/ASPNetProdListForm.aspx

8 <% dim strConn as string ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:\sales2k.mdb" dim objConn as new OledbConnection(strConn) dim strSQL as string = "select * from product;" Dim objComm As New OleDbCommand(strSQL, objConn) objConn.Open() Dim objDataReader As OleDbDataReader objDataReader = objComm.ExecuteReader() Do While objDataReader.Read() = True %> <% response.write ("PID = " & objDataReader("pid") & " ") response.write ("Descrition = " & objDataReader("description") & " ") response.write ("Price = " & objDataReader("price")) %> Qty: <% loop %>

9 Picture File Access: –OLE field –Picture file name Creating links to picture files Insert pictures in web page –IMG tag

10 Creating Links to Pictures sub Page_Load() dim strConn as string ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:\sales2k.mdb" dim objConn as new OledbConnection(strConn) dim strSQL as string = "select PicID, PicDescription, PicPath from PictureTable;" dim objComm as new OledbCommand(strSQL,objConn) objConn.open() dim objDataReader as oledbDataReader objDataReader=objComm.executeReader() do while objDataReader.Read=True response.write (" " & objDataReader("PicDescription") & " ") loop objConn.close() end sub

11 Insert Pictures sub Page_Load() response.write(" Available Pictures ") dim strConn as string ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:\sales2k.mdb" dim objConn as new OledbConnection(strConn) dim strSQL as string = "select PicID, PicDescription, PicPath from PictureTable;" dim objComm as new OledbCommand(strSQL,objConn) objConn.open() dim objDataReader as oledbDataReader objDataReader=objComm.executeReader() do while objDataReader.Read=True response.write (" ") loop objConn.close() end sub

12 Creating Forms with Images ASPNet/AspNetProdListFormPic.Aspx

13 ASP.Net Repeater Control The Repeater is a basic templated data-bound list. It has no built-in layout or styles, so you must explicitly declare all HTML layout, formatting, and style tags within the control's templates. The Repeater has no built-in editing support. The Repeater uses template to control formatting and data binding.

14 Repeater Control’s Templates Five types of templates: –HeaderTemplate, ItemTemplate, AlternatingItemTemplate, SeparatorTemplate, FooterTemplate Note 1: A Repeater binds its ItemTemplate and AlternatingItemTemplate to a DataSource. The HeaderTemplate, FooterTemplate, and SeparatorTemplate are not data-bound. Note 2: At a minimum, every Repeater must define an ItemTemplate.

15 Creating a Table Using Repeater To create a table using templates, include the begin table tag in the HeaderTemplate, a single table row tag and in the ItemTemplate, and the end table tag ( ) in the FooterTemplate.

16 Repeater Example Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:\sales2k.mdb" Dim objConn As New OledbConnection(strConn) Dim strSQL As String = "select * from customer;" Dim objComm As New OleDbCommand(strSQL, objConn) objConn.Open() Dim objDataReader As OleDbDataReader objDataReader = objComm.ExecuteReader() Repeater1.DataSource = objDataReader Repeater1.DataBind() End Sub

17 Note: Databinding tag

18 Creating a Table Using Repeater CID Cname City Rating

19 Creating Links Using Repeater Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:\sales2k.mdb" Dim objConn As New OledbConnection(strConn) Dim strSQL As String = "select * from product;" Dim objComm As New OleDbCommand(strSQL, objConn) objConn.Open() Dim objDataReader As OleDbDataReader objDataReader = objComm.ExecuteReader() Repeater1.DataSource = objDataReader Repeater1.DataBind() objConn.Close() End Sub

20 '>


Download ppt "ASP and HTML. Anchor Tag testAnchorTag Demo: ASPNet/ASPNETProdListSelf.ASPX."

Similar presentations


Ads by Google