PROWAREtech
ASP.NET: HtmlTable Server Control
HtmlTable server control example in VB.NET (.NET Framework).
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<html>
<head>
<title>HtmlTable Example</title>
</head>
<body>
<table id="tblExample" runat="server"></table>
</body>
</html>
'Default.aspx.vb
Imports System
Imports System.IO
Imports System.Collections
Imports System.Collections.Specialized
Imports System.Configuration
Imports System.Text
Imports System.Text.RegularExpressions
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Data
Imports System.Data.OleDb
Imports System.Configuration
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
tblExample.Style.Value = "border-width:1px;border-style:Solid;border-color:Black;"
tblExample.CellPadding = "3"
tblExample.CellSpacing = "1"
Dim tr As HtmlTableRow
Dim td As HtmlTableCell
tr = New HtmlTableRow
tr.BgColor = "#000080"
td = New HtmlTableCell
td.ColSpan = 7
td.Style.Value = "color:white;font-weight:bold;text-align:left;"
td.InnerHtml = "TITLES"
tr.Cells.Add(td)
tblExample.Rows.Add(tr)
tr = New HtmlTableRow
tr.BgColor = "#AAAAAA"
td = New HtmlTableCell
td.NoWrap = True
td.Style.Value = "font-weight:bold;text-align:center;"
td.InnerHtml = "Title ID"
tr.Cells.Add(td)
td = New HtmlTableCell
td.NoWrap = True
td.Style.Value = "font-weight:bold;text-align:center;"
td.InnerHtml = "Title"
tr.Cells.Add(td)
td = New HtmlTableCell
td.NoWrap = True
td.Style.Value = "font-weight:bold;text-align:center;"
td.InnerHtml = "Type"
tr.Cells.Add(td)
td = New HtmlTableCell
td.NoWrap = True
td.Style.Value = "font-weight:bold;text-align:center;"
td.InnerHtml = "Price"
tr.Cells.Add(td)
td = New HtmlTableCell
td.NoWrap = True
td.Style.Value = "font-weight:bold;text-align:center;"
td.InnerHtml = "YTD Sales"
tr.Cells.Add(td)
td = New HtmlTableCell
td.NoWrap = True
td.Style.Value = "font-weight:bold;text-align:center;"
td.InnerHtml = "Notes"
tr.Cells.Add(td)
td = New HtmlTableCell
tr.Cells.Add(td)
tblExample.Rows.Add(tr)
Dim oCon As New OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings("ConnectPubs").ToString())
oCon.Open()
'FROM THE pubs DATABASE IN MS SQL SERVER
Dim oCmd As New OleDbCommand("SELECT title_id,title,type,price,ytd_sales,notes FROM titles", oCon)
Dim oRdr As OleDbDataReader = oCmd.ExecuteReader()
Dim i As Integer = 0
While oRdr.Read()
tr = New HtmlTableRow
tr.BgColor = IIf(i Mod 2 = 0, "#CCFFCC", "#E0FFE0")
td = New HtmlTableCell
td.NoWrap = True
td.Style.Value = "font-weight:bold;"
td.InnerHtml = "" & oRdr(0)
tr.Cells.Add(td)
td = New HtmlTableCell
td.NoWrap = False
td.InnerHtml = "" & oRdr(1)
tr.Cells.Add(td)
td = New HtmlTableCell
td.NoWrap = True
td.InnerHtml = "" & oRdr(2)
tr.Cells.Add(td)
td = New HtmlTableCell
td.NoWrap = True
td.InnerHtml = String.Format("{0:c}", "0" & oRdr(3))
tr.Cells.Add(td)
td = New HtmlTableCell
td.NoWrap = True
td.InnerHtml = "" & oRdr(4)
tr.Cells.Add(td)
td = New HtmlTableCell
td.NoWrap = False
td.Style.Value = "font:7pt Arial;"
td.BgColor = IIf(i Mod 2 = 0, "#FFCCCC", "#FFE0E0")
td.InnerHtml = "" & oRdr(5)
tr.Cells.Add(td)
td = New HtmlTableCell
td.BgColor = IIf(i Mod 2 = 0, "#CCCCFF", "#E0E0FF")
td.InnerHtml = "<input type=""button"" id=""button" & oRdr(0) & _
""" onclick=""alert('you clicked '+this.id);"" " & _
"style=""height:15px;width:15px;border-color:green;background-color:green;"">"
tr.Cells.Add(td)
tblExample.Rows.Add(tr)
i += 1
End While
oRdr.Close()
oCon.Close()
End Sub
End Class
TITLES | ||||||
Title ID | Title | Type | Price | YTD Sales | Notes | |
BU1032 | The Busy Executive's Database Guide | business | $19.99 | 4095 | An overview of available database systems with emphasis on common business applications. Illustrated. | |
BU1111 | Cooking with Computers: Surreptitious Balance Sheets | business | $11.95 | 3876 | Helpful hints on how to use your electronic resources to the best advantage. | |
BU2075 | You Can Combat Computer Stress! | business | $2.99 | 18722 | The latest medical and psychological techniques for living with the electronic office. Easy-to-understand explanations. | |
BU7832 | Straight Talk About Computers | business | $19.99 | 4095 | Annotated analysis of what computers can do for you: a no-hype guide for the critical user. | |
MC2222 | Silicon Valley Gastronomic Treats | mod_cook | $19.99 | 2032 | Favorite recipes for quick, easy, and elegant meals. | |
MC3021 | The Gourmet Microwave | mod_cook | $2.99 | 22246 | Traditional French gourmet recipes adapted for modern microwave cooking. | |
MC3026 | The Psychology of Computer Cooking | UNDECIDED | $0.00 | |||
PC1035 | But Is It User Friendly? | popular_comp | $22.95 | 8780 | A survey of software for the naive user, focusing on the 'friendliness' of each. | |
PC8888 | Secrets of Silicon Valley | popular_comp | $20.00 | 4095 | Muckraking reporting on the world's largest computer hardware and software manufacturers. | |
PC9999 | Net Etiquette | popular_comp | $0.00 | A must-read for computer conferencing. | ||
PS1372 | Computer Phobic AND Non-Phobic Individuals: Behavior Variations | psychology | $21.59 | 375 | A must for the specialist, this book examines the difference between those who hate and fear computers and those who don't. | |
PS2091 | Is Anger the Enemy? | psychology | $10.95 | 2045 | Carefully researched study of the effects of strong emotions on the body. Metabolic charts included. | |
PS2106 | Life Without Fear | psychology | $7.00 | 111 | New exercise, meditation, and nutritional techniques that can reduce the shock of daily interactions. Popular audience. Sample menus included, exercise video available separately. | |
PS3333 | Prolonged Data Deprivation: Four Case Studies | psychology | $19.99 | 4072 | What happens when the data runs dry? Searching evaluations of information-shortage effects. | |
PS7777 | Emotional Security: A New Algorithm | psychology | $7.99 | 3336 | Protecting yourself and your loved ones from undue emotional stress in the modern world. Use of computer and nutritional aids emphasized. | |
TC3218 | Onions, Leeks, and Garlic: Cooking Secrets of the Mediterranean | trad_cook | $20.95 | 375 | Profusely illustrated in color, this makes a wonderful gift book for a cuisine-oriented friend. | |
TC4203 | Fifty Years in Buckingham Palace Kitchens | trad_cook | $11.95 | 15096 | More anecdotes from the Queen's favorite cook describing life among English royalty. Recipes, techniques, tender vignettes. | |
TC7777 | Sushi, Anyone? | trad_cook | $14.99 | 4095 | Detailed instructions on how to make authentic Japanese sushi in your spare time. |
Comment