Do not display table on form if field is null

M

Morris Neuman

Hi,

I have a table on a form with 2 rows only. The first row contains static
data and the second row contains a label which will be bound to a field
("MyField") in a database. The database access is done via AccessDataSource
or SQLDataSource control and a select statement retireves this field
"MyField".

I only want the table to be visible on the form if the bound field is not
null. How can I do that?

Sorry but I am having a hard time with binding label and textboxes to
datavalues.

As always, any help is appreciated.
 
S

Steven Cheng[MSFT]

Hi MOrris,

From your description, you want to make your Table(GridView ?) be visible
or invisible depend on the count of the data rows it will display, correct?

Assume you're using the GridView, you can consider use its "PreRender"
event to check the GridView.Rows.Count property and show or hide the
Gridview respectively. e.g.


=================
protected void GridView1_PreRender(object sender, EventArgs e)
{
if (GridView1.Rows.Count == 1)
{
GridView1.Visible = false;
}
else
{
GridView1.Visible = true;
}
}
===================


Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Morris Neuman

Hi, Thanks for the help.

My logic needed to be adjusted a bit so I modified your code a bit and it
works.

What is difference in putting code in pageload vs. pre-render?
 
S

Steven Cheng[MSFT]

Thanks for your reply Morris,

As for the "Load" event and "PreRender" event, they're firing at different
time in ASP.NET page request's processing pipeline. "Load" event fires when
the ASP.NET page has populated the initial control collection(also loaded
viewstate), but haven't processing the postback events. The "PreRender"
event will fire before the page render out, also it is the last place that
we can modify the page/control's states(that will be persisted).

#ASP.NET Page Life Cycle Overview
http://msdn2.microsoft.com/en-us/library/ms178472.aspx

Therefore, I would prefer to use PreRender to do some modification
(regardless of any modification prior to this event) and can make sure the
modification will be persisted.

Hope this also helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Morris Neuman

Thanks very much for the explanation. I have put the code in the PreRrender
event as recommended.
 

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
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top