0

How can I replace the text of a label control contained in a formview?

I've tried to use the code below:

Protected Sub FormViewNews_DataBound(sender As Object, e As System.EventArgs) Handles FormViewNews.DataBound
    Dim pagerRow As FormViewRow = FormViewNews.BottomPagerRow

    Dim Active As Label = CType(pagerRow.Cells(2).FindControl("OFMLabel"), Label)

    If Active = "False" Then
        Active = "Public"
    Else
        Active = "Private"
    End If
End Sub

But then I've got this error message: "Object reference not set to an instance of an object.".

i.e. I have a label named 'OFMLabel', and its valued 'TRUE'. Then, if TRUE, I want to change its text become 'PRIVATE', and if FALSE, become 'PUBLIC'.

Anyone can help me, please?

Thanks.

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by crishlay
0

Please try this:

Protected Sub FormViewNews_DataBound(sender As Object, e As System.EventArgs) Handles FormViewNews.DataBound
    Dim pagerRow As FormViewRow = FormViewNews.BottomPagerRow
 
    Dim Active As Label = CType(pagerRow.Cells(2).FindControl("OFMLabel"), Label)
 
    If Active.Text = "False" Then
        Active.Text = "Public"
    Else
        Active.Text = "Private"
    End If
End Sub
0

try below code for object reference problem

If Active.Text = "False" Then
Active.Text = "Public"
Else
Active.Text = "Private"
End If

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.