在下面的网格视图中,我不想显示“ID”,但我需要按它进行过滤。我怎么做?您会看到我正在尝试使用“IF”进行过滤,但这不起作用e.Row.Cells("ID").Text = "21"
?
Imports System.Data
Partial Class Default2
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
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(1100, "Dilantin", "Melanie", DateTime.Now)
table2.Rows.Add(125, "Indocin", "David", DateTime.Now)
table2.Rows.Add(150, "Enebrel", "Sam", DateTime.Now)
table2.Rows.Add(110, "Hydralazine", "Christoff", DateTime.Now)
GridView1.DataSource = table2
Dim s_Patient As BoundField = New BoundField
s_Patient.DataField = "Patient"
s_Patient.HeaderText = "Patient"
Dim s_Drug As BoundField = New BoundField
s_Drug.DataField = "Drug"
s_Drug.HeaderText = "Drug"
GridView1.Columns.Clear()
GridView1.Columns.Add(s_Patient)
GridView1.Columns.Add(s_Drug)
GridView1.AutoGenerateColumns = False
GridView1.DataBind()
End Sub
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow AndAlso (e.Row.Cells("ID").Text = "21" OrElse e.Row.Cells("ID").Text = "150") Then
e.Row.BackColor = Drawing.Color.Blue
End If
End Sub
结束类