0

方法: 青の背景色と「チェック」チェック ボックスのデータ行を追加し、残りは青の背景色のままにします

以下の私のコードを参照してください。助けてくれてありがとう

Dim table2 As New DataTable
' Create four typed columns in the DataTable.
table2.Columns.Add("ID", GetType(Integer))
table2.Columns.Add("Drug", GetType(String))
table2.Columns.Add("Patient", GetType(String))
table2.Columns.Add("Date", GetType(DateTime))
' Add five rows with those columns filled in the DataTable.
table2.Rows.Add(25, "Indocin", "David", DateTime.Now)
table2.Rows.Add(50, "Enebrel", "Sam", DateTime.Now)
table2.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now)
table2.Rows.Add(21, "Combivent", "Janet", DateTime.Now)
table2.Rows.Add(10, "Dilantin", "Melanie", DateTime.Now)
table2.Rows.Add(125, "Indocin", "David", DateTime.Now)
table2.Rows.Add(150, "Enebrel", "Sam", DateTime.Now)
table2.Rows.Add(2, "Hydralazine", "Christoff", DateTime.Now)

'GridView1.DataSource = table2



For Each dr As DataRow In table2.Rows

    If dr("ID") = 21 Or dr("ID") = 150 Then

        ' add  a data row with a back ground colour - blue and check check box

    Else

        ' add  a data row with a back ground colour - yellow

    End If




Next

GridView1.DataBind()
4

2 に答える 2

2

DataTable を GridView にバインドし、RowDataBound Eventを介して処理します。

Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles GridView1.RowDataBound

    'Assuming your ID column is in the first cell.
    If e.Row.RowType = DataControlRowType.DataRow AndAlso _
       (e.Row.Cells(0).Text = "21" OrElse e.Row.Cells(0).Text = "150") Then

        e.Row.BackColor = Drawing.Color.Blue

        'Assuming CheckBox is in the second cell with ID of "IdOfCheckBox"
        CType(e.Row.Cells(1).FindControl("IdOfCheckBox"), CheckBox).Checked = True

    End If

End Sub
于 2012-09-06T21:13:11.900 に答える
1
Sub GridView_RowDataBound(ByVal sender As Object, _
  ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)

    If e.Row.RowType = DataControlRowType.DataRow Then
                If (Check your condition ) Then
                e.Row.BackColor = Drawing.Color.Blue
                'Then find your checkbox control from row and set it's value to Checked...

   ELSE
     e.Row.BackColor = Drawing.Color.yellow

 End If
    End If
End Sub
于 2012-09-06T21:10:35.257 に答える