Do not display table on form if field is null

Discussion in 'ASP .Net Web Controls' started by Morris Neuman, Apr 12, 2007.

  1. 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
     
    Morris Neuman, Apr 12, 2007
    #1
    1. Advertising

  2. 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.
     
    Steven Cheng[MSFT], Apr 13, 2007
    #2
    1. Advertising

  3. 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/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.
    >
    >
     
    Morris Neuman, Apr 16, 2007
    #3
  4. 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.
     
    Steven Cheng[MSFT], Apr 17, 2007
    #4
  5. 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.
    >
    >
    >
    >
    >
     
    Morris Neuman, Apr 17, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page