I need your assistance please

G

Guest

Hi,
I am trying to check a value of a contril in my gridview but this %$%&^^&*
thing is driving me nuts.

I tried

Dim t As TextBox = CType(e.Row.Cells(16).FindControl("Status"), TextBox)
If t.text = "N" Then
e.Row.Cells(16).Controls(1).Visible = True
End If

This crap doesn't work. I get either Object not set to instance BS or can
cast from literal to system.web.ui crap.

The column is a template column with 2 controls, one label control and
another is a checkbox. I want to set the checkbox to visible only when the
label control says "N" and at the same time make the label contril visible =
flase.

Please assist.

Thanks
 
M

Mark Rae [MVP]

I am trying to check a value of a contril in my gridview but this %$%&^^&*
thing is driving me nuts.

I tried

Dim t As TextBox = CType(e.Row.Cells(16).FindControl("Status"), TextBox)
If t.text = "N" Then
e.Row.Cells(16).Controls(1).Visible = True
End If

This crap doesn't work. I get either Object not set to instance BS or can
cast from literal to system.web.ui crap.

I'm not surprised! The above code is indeed crap - I suggest you fire the
idiot who wrote it...

The main problem, of course, is that the cell in question contains a Label
control which the above code is trying to CType to a TextBox...

Dim l As Label = CType(e.Row.Cells(16).FindControl("Status"), Label)
If l.Text = "N" Then
e.Row.Cells(16).Controls(1).Visible = True
e.Row.Cells(16).Controls(0).Visible = False
End If
 
G

Guest

The code is similar to yours except it was tried against a text box as well.
Even with yours didn't work. Eventually adding .Trim() worked! Pardon my
frustration.

Dim t As TextBox = CType(e.Row.Cells(16).FindControl("Status"),
TextBox)
If t.text.Trim() = "N" Then
e.Row.Cells(16).Controls(1).Visible = True
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top