grabbing a control in a datagrid.

  • Thread starter Thread starter David Lozzi
  • Start date Start date
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
 
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;
 
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
 
Back
Top