1 / 20

ASP and HTML

ASP and HTML. Anchor Tag. <a href= "http://www.yahoo.com/" > testAnchorTag </a> Demo: ASPNet/ASPNETProdListSelf.ASPX. Creating Links. <p> Click a link to view a product: </p> <% dim strConn as string ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:sales2k.mdb"

brooke
Download Presentation

ASP and HTML

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ASP and HTML

  2. Anchor Tag • <a href="http://www.yahoo.com/">testAnchorTag</a> • Demo: ASPNet/ASPNETProdListSelf.ASPX

  3. Creating Links <p>Click a link to view a product:</p> <% 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 ("<p><a href='http://dchaolaptop/aspnet/aspnetshowprod.aspx?" & "pid=" & objDataReader("pid") & "'>" & objDataReader("description") & "</a></p><br>") loop %>

  4. Program that Response to links <body> <% 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") & "<br>") response.write ("Descrition = " & objDataReader("description") & "<br>") response.write ("Price = " & objDataReader("price")) %> <form method="POST" action="addToCart.aspx"> <p>Qty: <input type="text" name="qty" size="20"></p> <p><input type="submit" value="AddToCart" name="B1"><input type="reset" value="Reset" name="B2"></p> </form> </body>

  5. Links that Reference Itself <body> <p>Click a link to view a product:</p> <% 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 ("<p><a href='http://dchaolaptop/aspnet/aspnetProdListSelf.aspx?" & "pid=" & objDataReader("pid") & "'>" & objDataReader("description") & "</a></p><br>") loop %> </body> 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") & "<br>") response.write ("Descrition = " & objDataReader("description") & "<br>") 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 %> <form method="POST" action="addToCart.aspx" style="border-style: double"> <% response.write ("PID = " & objDataReader("pid") & "<br>") response.write ("Descrition = " & objDataReader("description") & "<br>") response.write ("Price = " & objDataReader("price")) %> <p>Qty: <input type="text" name="qty" size="20"></p> <p><input type="submit" value="AddToCart" name="B1"><input type="reset" value="Reset" name="B2"></p> <input type="hidden" name="HiddenPID" value=objDataReader("pid")> </form> <% 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 <script runat="server"> 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 ("<p><a href='http://dchaolaptop/images/" & objDataReader("PicPath") & "'>" & objDataReader("PicDescription") & "</a></p><br>") loop objConn.close() end sub </script>

  11. Insert Pictures <script runat="server"> sub Page_Load() response.write("<p align='center'><font size='5'><b>Available Pictures</b></font></p>") 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 ("<p><img border='0' src='http://dchaolaptop/images/" & objDataReader("PicPath") & "' width='198' height='151'></p>") loop objConn.close() end sub </script>

  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 <table> in the HeaderTemplate, a single table row tag <tr> and <td> in the ItemTemplate, and the end table tag (</table>) 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. <form id="Form1" method="post" runat="server"> <asp:Repeater id="Repeater1" runat="server"> <ItemTemplate> <%# container.dataItem("cname") %> </ItemTemplate> <AlternatingItemTemplate> <font color="#ff33ff#"> <%# container.dataItem("cname") %> </font> </AlternatingItemTemplate> <SeparatorTemplate> <hr> </SeparatorTemplate> </asp:Repeater> </form> Note: Databinding tag <%# Container.DataItem(“Cname”) %>

  18. Creating a Table Using Repeater <asp:Repeater id="Repeater1" runat="server"> <HeaderTemplate> <table border=1> <tr bgcolor=LightGrey> <th>CID</th> <th>Cname</th> <th>City</th> <th>Rating</th> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td> <%# container.dataItem("cid") %></td> <td> <%# container.dataItem("cname") %></td> <td> <%# container.dataItem("city") %></td> <td> <%# container.dataItem("rating") %></td> </tr> </ItemTemplate> <AlternatingItemTemplate> <tr bgcolor=#ff00ff> <td> <%# container.dataItem("cid") %></td> <td> <%# container.dataItem("cname") %></td> <td> <%# container.dataItem("city") %></td> <td> <%# container.dataItem("rating") %></td> </tr> </AlternatingItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater>

  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. <form id="Form1" method="post" runat="server"> <asp:Repeater id="Repeater1" runat="server"> <ItemTemplate> <p><a href='http://dchaolaptop/aspnet/aspnetshowprod.aspx?pid=<%# container.dataItem("pid") %>'><%# container.dataItem("description") %></a></p><br> </ItemTemplate> </asp:Repeater> </form>

More Related