grabbing a control in a datagrid.

D

David Lozzi

howdy,

trying to do the following

dg.FindControl("add_Name").visible = true

This control is located in the footer of a column. I am trying to have it
appear under certain circumstances. The function fires that contains this
script under my circumstance, however I get the following error about this
script:

System.NullReferenceException: Object reference not set to an instance of an
object


Thanks a ton!!

David Lozzi
 
D

dinil

try this

HyperLink hl1 = new HyperLink();

DataGridItem dgi= (DataGridItem)
DataGrid1.Controls[0].Controls[DataGrid1.Controls[0].Controls.Count-1];

hl1= (HyperLink)dgi.FindControl("HyperLink1");

hl1.Visible=false;
 
D

David Lozzi

Thank you so much, that worked like a charm. However, I'm writing this in
VB.net, sorry I did not specify earlier. Below is the VB version of what you
wrote. Also, you miss typed the assigning of the controls to the dgi object,
unless C# somehow magically does that ??

.. Dim opt As DropDownList = sender
Dim dg As DataGrid = dgEvals
Dim txtother As New TextBox
Dim dgi As DataGridItem
dgi =
dgEvals.Controls(0).Controls(dgEvals.Controls(0).Controls.Count - 1)
txtother = dgi.FindControl("add_EvalOther")

If opt.SelectedValue = "Other" Then
txtother.Visible = True
Else
txtother.Visible = False
End If

THANK YOU!


dinil said:
try this

HyperLink hl1 = new HyperLink();

DataGridItem dgi= (DataGridItem)
DataGrid1.Controls[0].Controls[DataGrid1.Controls[0].Controls.Count-1];

hl1= (HyperLink)dgi.FindControl("HyperLink1");

hl1.Visible=false;



David Lozzi said:
howdy,

trying to do the following

dg.FindControl("add_Name").visible = true

This control is located in the footer of a column. I am trying to have it
appear under certain circumstances. The function fires that contains this
script under my circumstance, however I get the following error about
this
script:

System.NullReferenceException: Object reference not set to an instance of an
object


Thanks a ton!!

David Lozzi
 

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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top