开发者

changing the forecolor at runtime of label which is present in template field of gridview in asp.net

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开发者_如何学C 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?


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜