如何给ASP.NET的Table控件换皮肤?

时间:2008-06-28 23:31:03  来源:  作者:
 范例二:第二个 Table 控制项 (依“储存格”数值变化,动态显示不同颜色),执行画面如上图 2


<%@ Import Namespace =Namespace="System.Data" %>
<%@ Import Namespace =Namespace="System.Data.OleDb" %>
<script Language="VB" runat="server">
Sub Page_Load()Sub Page_Load(sender As Object, e As EventArgs) 
 Dim myConn As OleDbConnection
 Dim myCmd As OleDbCommand 
 Dim myRd As OleDbDataReader
     …中间略…
 ' DataReader 物件连结“股票行情表”资料表
 myRd = myCmd.ExecuteReader()
 ' 呼叫副程式,利用 DataReader 物件逐栏逐列读取资料表,然后填入输出用的表格
 OutputToTable( myRd )
 ' 关闭资料库连线
 myConn.Close()
End Sub
Sub OutputToTable()Sub OutputToTable( Rd As OleDbDataReader )
 Dim I As Integer
 Dim row As TableRow
 Dim cell As TableCell
 ' 将资料表的“抬头”填入表格中 
 row = New TableRow()
 row.BackColor = Drawing.Color.Gold
 For I = 0 To Rd.FieldCount - 1
  cell = New TableCell()
  cell.Text = Rd.GetName(I)  ' 将 DataReader 所读取的第 I 栏栏位抬头设定给 TableCell
  row.Cells.Add( cell )     ' 将 TableCell 加入 TableRow 之中
 Next
 Table2.Rows.Add( row )
 ' 逐列读出资料表,再将资料依序填入表格中
 While Rd.Read()
  row = New TableRow()
  For I = 0 To Rd.FieldCount - 1
   cell = New TableCell()
   cell.Text = Rd.Item(I)   ' 将 DataReader 所读取的第 I 栏资料设定给 TableCell
   row.Cells.Add( cell )    ' 将 TableCell 加入 TableRow 之中
   If (I=0) Then
    cell.BackColor=Drawing.Color.Goldenrod
    cell.ForeColor=Drawing.Color.SteelBlue
   End IF
   If (I=Rd.FieldCount-4) And Val(cell.Text)>0 Then 
    cell.BackColor=Drawing.Color.Red
    cell.ForeColor=Drawing.Color.Pink 
   ElseIf (I=Rd.FieldCount-4) And Val(cell.Text)<0 Then 
    cell.BackColor=Drawing.Color.LawnGreen
    cell.ForeColor=Drawing.Color.GhostWhite
   End If
   If (I=Rd.FieldCount-3) And Val(cell.Text)>20 Then 
    cell.BackColor=Drawing.Color.Pink
    cell.ForeColor=Drawing.Color.Red 
   End If
   If (I=Rd.FieldCount-2) And Val(cell.Text)>17 Then 
    cell.BackColor=Drawing.Color.Pink
    cell.ForeColor=Drawing.Color.Red 
   End If
   If (I=Rd.FieldCount-1) And Val(cell.Text)>2000 Then 
    cell.BackColor=Drawing.Color.Red
    cell.ForeColor=Drawing.Color.Pink 
   ElseIf (I=Rd.FieldCount-1) And Val(cell.Text)>200 Then 
    cell.BackColor=Drawing.Color.HotPink
    cell.ForeColor=Drawing.Color.LightSteelBlue
   End If 
  Next 
  Table2.Rows.Add( row )   ' 将 TableRow 加入 Table 之中
 End While
End Sub 
</script>


Tags:


上一篇:没有了   下一篇:没有了

文章评论

共有 0人发表了评论 查看完整内容

推荐教程

最新教程