Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Do not display table on form if field is null

Reply
Thread Tools

Do not display table on form if field is null

 
 
Morris Neuman
Guest
Posts: n/a
 
      04-12-2007
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.

--
Thanks
Morris
 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      04-13-2007
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/subscripti...ult.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/subscripti...t/default.aspx.

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



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

 
Reply With Quote
 
 
 
 
Morris Neuman
Guest
Posts: n/a
 
      04-16-2007
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?
--
Thanks
Morris


"Steven Cheng[MSFT]" wrote:

> 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/subscripti...ult.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/subscripti...t/default.aspx.
>
> ==================================================
>
>
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>

 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      04-17-2007
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.




 
Reply With Quote
 
Morris Neuman
Guest
Posts: n/a
 
      04-17-2007
Thanks very much for the explanation. I have put the code in the PreRrender
event as recommended.
--
Thanks
Morris


"Steven Cheng[MSFT]" wrote:

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
javascript validation for a not required field, field is onlyrequired if another field has a value jr Javascript 3 07-08-2010 10:33 AM
1.Enter space bar for field names and save the field.The field shoud not get saved and an alert should be there as"Space bars are not allowed" Sound Javascript 2 09-28-2006 02:43 PM
"stringObj == null" vs "stringObj.equals(null)", for null check?? qazmlp1209@rediffmail.com Java 5 03-29-2006 10:37 PM
Pass hidden form field value to another form field to insert in db GavMc ASP General 4 09-22-2005 06:33 PM
copy and paste form RTF document into field in asp form cause it to bypass field length and javascript validation - how to overcome? NotGiven ASP General 3 05-13-2004 12:15 AM



Advertisments