Setting Visibility on Gridview items after they are created?

  • Thread starter Thread starter jc
  • Start date Start date
J

jc

I have a situation where I need to condition gridview item visibilty
after they've been created and after a textbox on page has a value.
What's the best way to do this in VB.NET? Any code sample?

I would imagine i have to loop through the control to do this.

Seems like it might be messy.
 
I suppose the looping of control hierarchy is the single way,
because your items are inside other control and u need find them somehow
 
Do it in the PreRender event.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Michael Nemtsev said:
I suppose the looping of control hierarchy is the single way,
because your items are inside other control and u need find them somehow

--
WBR, Michael Nemtsev [.NET/C# MVP].
Blog: http://spaces.live.com/laflour



jc said:
I have a situation where I need to condition gridview item visibilty
after they've been created and after a textbox on page has a value.
What's the best way to do this in VB.NET? Any code sample?

I would imagine i have to loop through the control to do this.

Seems like it might be messy.
 
Does anybody have any vb.net example of looping through the gridview
and setting visibility of an item after it's been built?
 
Does anybody have any vb.net example of looping through the gridview
and setting visibility of an item after it's been built?

I think you can do something like this (in C#, I am not good at VB):

foreach (GridViewRow gvr in MyGridView.Rows)
{
// If you know the column index, you can do:
gvr.Cells[2].Visible = false;
// Or if you want to make some control in that cell
invisible:
TextBox myTextBox = (TextBox)gvr.FindControls("myTextBox");
myTextBox.Visible = false;
}

The code hasn't been tested, but you get the idea.
 
Back
Top