Setting Visibility on Gridview items after they are created?

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.
 
M

Michael Nemtsev

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

Eliyahu Goldin

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.
 
J

jc

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

gnewsgroup

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.
 

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