开发者

changing the css dynamically in asp.net

开发者 https://www.devze.com 2023-03-11 14:51 出处:网络
I have a gridview inside an update panel.In that gridview, I have a linkbutton in which i need to show the status.If the linkbutton text is success then it should be in same color. and if the linkbutt

I have a gridview inside an update panel.In that gridview, I have a linkbutton in which i need to show the status.If the linkbutton text is success then it should be in same color. and if the linkbutton text is fail,it shou开发者_运维知识库ld be in red color.I have written the css for red color.

Here the default is blue.How to change it red when the linkbutton returns false??

Thanks


You could use GridView's RowDataBound event to change the CSS accordingly.

Private Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
    Select Case e.Row.RowType
        Case DataControlRowType.DataRow
            Dim data = DirectCast(e.Row.DataItem, DataRowView)
            Dim LnkStatus = DirectCast(e.Row.FindControl("LnkStatus "), LinkButton)
            If data("Status").ToString.ToLower = "fail" Then
                LnkStatus.CssClass = "FailedStatus"
            End If
    End Select
End Sub
0

精彩评论

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