【发布时间】:2011-08-04 02:54:21
【问题描述】:
我正在尝试通过 gridview 中的行遍历数据集的值,如果该行匹配,则在文本中着色。
下面的代码有效,但是每当我通过PageIndexChanging 更改页面并且再次运行此函数时,着色不再起作用。如果有匹配,它仍然循环通过gridview,但没有显示效果。
--variable initialization class instantiation--
--code to connect to db here--
mySQLCommand.CommandText = "SELECT ..."
mySQLAdapter = New SqlDataAdapter(mySQLCommand)
mySQLAdapter.Fill(myDataset)
Me.MainPageGridView.DataSource = myDataset
Me.MainPageGridView.DataBind()
mySQLCommand.CommandText = "SELECT ... The ID's to be matched"
mySQLAdapter = New SqlDataAdapter(mySQLCommand)
mySQLAdapter.Fill(myDatasetNew)
Me.MainPageGridView.DataSource = myDatasetNew
For Each dataRow In myDataset.Tables(0).Rows
thisID = dataRow("ID").ToString
For Each gvRow In Me.MainPageGridView.Rows
If gvRow.Cells(2).Text = thisID Then
For column = 0 To 14 Step 1
gvRow.Cells(column).ForeColor = Drawing.Color.RosyBrown
Next
Exit For
End If
Next
Next
【问题讨论】:
-
为什么要将两个数据集绑定到同一个网格?
标签: asp.net vb.net gridview page-index-changed