- 題名: tableコントールのセル内にtableを作りたい
- 日時: 2008/11/01 16:32:38
- ID: 23290
- この記事の返信元:
- (なし)
- この記事への返信:
- [23294] Re[1]: tableコントールのセル内にtableを作りたい2008/11/02 1:04:45
- ツリーを表示
サンプルを書いてみました。苦しいコードではありますが、参考になれば幸いです。 # もし外れていたらすみません。m(_ _)m <%@ Page Language="VB" AutoEventWireup="false" CodeFile="BarGraphTest.aspx.vb" Inherits="BarGraphTest" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>無題のページ</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Table ID="Table1" runat="server"> </asp:Table> <br /> </div> </form> </body> </html> Partial Class BarGraphTest Inherits System.Web.UI.Page Protected Overrides Sub OnLoad(ByVal e As System.EventArgs) MyBase.OnLoad(e) ' 表にセルを追加 With Me.Table1 .BorderStyle = BorderStyle.Solid .CellSpacing = 0 .BorderWidth = 2 .BorderColor = Drawing.Color.Blue End With For i As Integer = 1 To 15 Dim tr As New TableRow For j As Integer = 0 To 10 Dim tc As New TableCell If j = 0 Then tc.Width = 100 Else tc.Width = 40 tc.Height = 20 tc.BorderWidth = 1 tc.BorderColor = Drawing.Color.Black tr.Cells.Add(tc) Next Me.Table1.Rows.Add(tr) Next ' 各行の文字列と棒グラフの長さ Dim captions As String() = {"項目1", "項目2", "項目3", "項目4", "項目5"} Dim values As Integer() = {3, 0, 7, 10, 5} ' RowSpanを3にする For i As Integer = 0 To 4 Me.Table1.Rows(i * 3).Cells(0).Text = captions(i) Me.Table1.Rows(i * 3).Cells(0).RowSpan = 3 Me.Table1.Rows(i * 3 + 1).Cells(0).Visible = False Me.Table1.Rows(i * 3 + 2).Cells(0).Visible = False Next ' 棒グラフ描画 For i As Integer = 0 To 4 For j As Integer = 1 To 10 Dim tc1 As TableCell = Me.Table1.Rows(i * 3).Cells(j) Dim tc2 As TableCell = Me.Table1.Rows(i * 3 + 1).Cells(j) Dim tc3 As TableCell = Me.Table1.Rows(i * 3 + 2).Cells(j) tc1.Style.Add("border-bottom-style", "none") tc2.Style.Add("border-top-style", "none") tc2.Style.Add("border-bottom-style", "none") tc3.Style.Add("border-top-style", "none") If j <= values(i) Then tc2.BackColor = Drawing.Color.Red Else tc2.BackColor = Drawing.Color.White End If Next Next End Sub End Class
分類:[ASP.NET]