Reputation: 5
I am creating one application using gridview of asp.net. Grid view containing one template which having 3 to 4 labels which bind from database values.One label of gridview tamplate forecolor is blue but after selecting row i want to change color to white to selected row label to white but my problem is all other label colors is changed but that blue color label color is remaining. I am using following code to change color of all labels At gridview selectedindex changed event. For i As Integer = 0 To GridView1.Rows.Count - 1 If i = GridView1.SelectedIndex Then
GridView1.SelectedRow.Attributes.Add("style", "background-image: url('images/weight-loss-li-over.gif'); color : white;")
Else
GridView1.Rows(i).ForeColor = Drawing.Color.Black
GridView1.Rows(i).Font.Bold = False
GridView1.Rows(i).Attributes.Remove("style")
End If
Next
pls give me any answer?
Upvotes: 0
Views: 1377
Reputation: 2832
You have to change your code as follwos, i think it will help you.
For i As Integer = 0 To GridView1.Rows.Count - 1
Dim txt As Label = DirectCast(GridView1.Rows(i).Cells(0).FindControl("lblProgram"), Label)
If i = GridView1.SelectedIndex Then
txt.ForeColor = Drawing.Color.White
GridView1.SelectedRow.Attributes.Add("style", "background-image: url('images/weight-loss-li-over.gif'); color: white;")
Else
GridView1.Rows(i).ForeColor = Drawing.Color.Black
txt.ForeColor = Drawing.Color.Blue
GridView1.Rows(i).Attributes.Remove("style")
End If
Next
If it not resolve your problem then let me know.
Upvotes: 1
Reputation: 7367
Why you don't try CSS or JavaScript approches?
CSS hover: http://www.w3schools.com/cssref/sel_active.asp
JavaScript onClick: http://www.w3schools.com/jsref/event_onclick.asp
Upvotes: 0