2011-02-07 13 views
1

私は学習しています。そして、コードの背後からテーブルを作成し、代替の行の色を変更しようとしています。asp:テーブルの行の色をプログラムで変更します。

私はそれが働いていますが、筆者はDrawing.Colorだけを使用して16進数値を使用したいときは、これを行う方法がありますか?ここで

は、現時点ではそれをやってコードのthatsです:任意の助け

' declare variables 
    Dim numrows As Integer 
    Dim numcells As Integer 
    Dim i As Integer 
    Dim j As Integer 
    Dim r As TableRow 
    Dim c As TableCell 
    Dim hc As TableHeaderCell 
    'Dim datepickJS As String 

    ' generate rows and cells 
    numrows = CaseTotal 
    ' column count 
    numcells = 7 

    r = New TableRow() 
    c = New TableCell() 

    '' validation creation 
    'Dim newValidatorSummary As New ValidationSummary() 
    'newValidatorSummary.CssClass = "form-error" 
    'c.Controls.Add(newValidatorSummary) 
    'c.ColumnSpan = 5 
    'r.Cells.Add(c) 
    'Table1.Rows.Add(r) 


    r = New TableRow() 

    ' header row and titles 
    hc = New TableHeaderCell() 
    hc.Controls.Add(New LiteralControl("Case Ref")) 
    r.Cells.Add(hc) 
    hc = New TableHeaderCell() 
    hc.Controls.Add(New LiteralControl("Name")) 
    r.Cells.Add(hc) 
    hc = New TableHeaderCell() 
    hc.Controls.Add(New LiteralControl("Company")) 
    r.Cells.Add(hc) 
    hc = New TableHeaderCell() 
    hc.Controls.Add(New LiteralControl("Last Updated")) 
    r.Cells.Add(hc) 
    hc = New TableHeaderCell() 
    hc.Controls.Add(New LiteralControl("Order Date")) 
    r.Cells.Add(hc) 
    hc = New TableHeaderCell() 
    hc.Controls.Add(New LiteralControl(" ")) 
    r.Cells.Add(hc) 
    hc = New TableHeaderCell() 
    hc.Controls.Add(New LiteralControl(" ")) 
    r.Cells.Add(hc) 
    Table1.Rows.Add(r) 

    r.BackColor = Drawing.Color.AntiqueWhite 


    For j = 0 To numrows - 1 

     r = New TableRow() 
     'Table1.Rows(j).Cells(i).CssClass = "tablehead" 

     'row data 
     Dim ClientName, Company As String 
     Dim OrderDate As Date 
     ClientName = dsCases.Tables("CaseList").Rows(j).Item("firstname") & " " & dsCases.Tables("CaseList").Rows(j).Item("lastname") 
     Company = dsCases.Tables("CaseList").Rows(j).Item("company") 
     OrderDate = dsCases.Tables("CaseList").Rows(j).Item("CaseSent") 

     'create details button 
     Dim btnDetails As New Button() 
     btnDetails.Text = "Details" 
     btnDetails.ID = "btnDetails" 
     btnDetails.Width = "60" 
     btnDetails.Font.Size = "8" 
     'AddHandler btnSubmit.Click, AddressOf sendDetails_Click 

     'create schedule button 
     Dim btnSchedule As New Button() 
     btnSchedule.Text = "Schedule" 
     btnSchedule.ID = "btnSchedule" 
     btnSchedule.Width = "60" 
     btnSchedule.Font.Size = "8" 
     'AddHandler btnSubmit.Click, AddressOf sendDetails_Click 

     For i = 0 To numcells - 1 

      Dim iMod As Integer 
      iMod = j Mod 2 

      c = New TableCell() 


      If i = 0 Then 
       c.Controls.Add(New LiteralControl(iMod & " ")) 
       c.Controls.Add(New LiteralControl(UserId)) 

      ElseIf i = 1 Then 

       c.Controls.Add(New LiteralControl(ClientName)) 

      ElseIf i = 2 Then 

       c.Controls.Add(New LiteralControl(Company)) 

      ElseIf i = 3 Then 



      ElseIf i = 4 Then 

       c.Controls.Add(New LiteralControl(FormatDateTime(OrderDate, DateFormat.ShortDate))) 

      ElseIf i = 5 Then 

       c.Controls.Add(btnDetails) 

      ElseIf i = 6 Then 

       c.Controls.Add(btnSchedule) 

      End If 

      r.Cells.Add(c) 
     Next i 

     Table1.Rows.Add(r) 


     If j Mod 2 = 1 Then 
      r.BackColor = Drawing.Color.Aquamarine 
      'Table1.Rows(j).Cells(i).CssClass = "odd" 
     Else 
      r.BackColor = Drawing.Color.Blue 
      'Table1.Rows(j).Cells(i).CssClass = "even" 
     End If 

    Next j 

    r = New TableRow() 

    ' footer row 
    c = New TableCell() 
    c.ColumnSpan = 7 
    c.HorizontalAlign = HorizontalAlign.Right 
    r.Cells.Add(c) 
    Table1.Rows.Add(r) 

ありがとう:

ここ
 If j Mod 2 = 1 Then 
      r.BackColor = Drawing.Color.Aquamarine 
      'Table1.Rows(j).Cells(i).CssClass = "odd" 
     Else 
      r.BackColor = Drawing.Color.Blue 
      'Table1.Rows(j).Cells(i).CssClass = "even" 
     End If 

は完全なコードです。ここ

r.BackColor = ColorTranslator.FromHtml("#0000FF") 

ドキュメント:

J.

答えて

関連する問題