By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,180 Members | 1,012 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,180 IT Pros & Developers. It's quick & easy.

PreRender checking value in textbox before making gridiview itemvisible

P: n/a
jc
Hello.

I have a gridview column item that i want to not make visible if the
bound data in that cell is less than a value in a textbox.

However, I notice at the time my code checks a function that I call
from the visible property of the gridview itemtemplate, the textbox is
always blank.

I tried setting the textbox in the prerender, but I suspect the
gridview is built much earlier in another event.. like items created.

Whats the best way to attack this?

Also, and a question I can't believe I'm asking.. what's the preferred
way to store information in a codebehind variable so that's a
available across all subs, functions and events? For example, if I
want to have something in a variable I set in the prerender, how do I
make that available in Page load sub?
Dec 11 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
PreRender is the right place for this. At this stage the grid has already
been fully built, which is your advantage rather than a disadvantage since
no-one will intervene in the final changes you are making there.

PreRender event fires after Load, so it won't help if you set something in
PreRender. Otherwise, if you just declare a field or a property in your page
class it will be visible by all other members.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"jc" <jo**@webdos.comwrote in message
news:b3**********************************@f3g2000h sg.googlegroups.com...
Hello.

I have a gridview column item that i want to not make visible if the
bound data in that cell is less than a value in a textbox.

However, I notice at the time my code checks a function that I call
from the visible property of the gridview itemtemplate, the textbox is
always blank.

I tried setting the textbox in the prerender, but I suspect the
gridview is built much earlier in another event.. like items created.

Whats the best way to attack this?

Also, and a question I can't believe I'm asking.. what's the preferred
way to store information in a codebehind variable so that's a
available across all subs, functions and events? For example, if I
want to have something in a variable I set in the prerender, how do I
make that available in Page load sub?

Dec 12 '07 #2

P: n/a
jc
would anybody have an example of how I can loop through the grid and
change visibility of items after it's been built?
Dec 12 '07 #3

P: n/a
On Dec 12, 6:55 am, jc <j...@webdos.comwrote:
would anybody have an example of how I can loop through the grid and
change visibility of items after it's been built?
Sounds like you can use a RowDataBound event handler like so (very
sketchy code, but you get the idea.)

protected void MyGridView_RowDataBound(object s,
GridViewRowEventArgs e)
{
// Hide the header of the leftmost column.
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[0].Visible = false;
}

// Hide the leftmost column of the data row.
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].Visible = false;
}
}
Dec 12 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.