最后我找到了一个窍门。我不确定这是否是正确的方法,但它对我有用。
Protected Sub GridView6_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView6.RowCommand
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim r As GridViewRow = GridView6.Rows(index)
Dim cell1 As Button = r.Cells(0).Controls(0)
Dim c1 As String = RTrim(cell1.Text)
Dim cell2 As Button = r.Cells(1).Controls(0)
Dim c2 As String = RTrim(cell2.Text)
Dim cell3 As Button = r.Cells(2).Controls(0)
Dim c3 As String = RTrim(cell3.Text)
Dim cellname As String = RTrim(e.CommandName)
If c1 = cellname Then
If cell1.BackColor = Drawing.Color.OliveDrab Then
cell1.BackColor = Drawing.Color.Linen
Else
cell1.BackColor = Drawing.Color.OliveDrab
End If
End If
// AND same for C2 and C3
它既可以着色又可以变色;)