.NET Answers

ASP.NET, HTML, CSS, Visual Studio, CSharp, VB.NET and other programming items of interest.
Subscribe
  • Home
  • About Me
  • Advertising
  • Click Here to Ask a question
    • Privacy Policy
  • Site Map

Conditional Footnotes On GridView

September 25, 2008 By: Dave

hand-079 A couple of days ago I ran into a requirement to conditionally display footnote information at the bottom of a GridView display.  We were already conditionally displaying icons in the row.  What we needed to do was to conditionally show text at the bottom of the screen that explained what each icon was for.  Here’s how we went about it.

The first thing we did was to make all of the footnotes invisible.  We will only make them visible if the associated icon is visible.  So we need some way of determining if the icon is visible, and if it is we need to make the associated footnote visible.

First, we find out if the icon is visible.

There is an event that fires every time a row is created in the GridView control.  The event name is RowCreated.  This event sends the sender object and a GridViewRowEventArgs object down to the handler.  And this is where the magic starts.

There are two ways of finding a control in the row.  You can go after it using:

e.Row.Cells[cellControlIsIn].Controls[indexOfTheControl];

Which you can then cast to the type of control you are expecting and check the Visible property to see if it is visible.

The other thing you can do is recursively look for the control by its ID by iterating through the Controls collection of each control in the Row.

We’ve written a utility function that does all the work:

public static Control
    FindControlByID(string id,
    ControlCollection controls)
{
    Control returnControl = null;
    foreach (Control c in controls)
    {
        if (c.ID == id)
            return c;

        returnControl =
            FindControlByID(id, c.Controls);
        if (returnControl != null)
            return returnControl;
    }
    return returnControl;
}

If you want the absolute fastest code, you’ll use the first method.  If you just want to get the code working and out the door, you can use the second method.

Once we know that the control is visible, we can set the footnote visible in the event handler and we are done.

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

Related Post

  • GridViews – Multiple Rows Per Record
  • Editing in a GridView without switching to Edit mode.
  • jQuery – Date Picker
Bookmark to:

Add to Del.icio.us Add to digg Add to DotNetKicks Add to DZone Add to Facebook Add to Slashdot Add to Stumble Upon Add to Technorati
Hide Sites
Tags: asp.net, event handling, findcontrolbyid, gridview, repeater controls

Comments are closed.

← DotNetNuke Modules – Retrieving Settings
Friday Books – Rapid Development →
  • Search

  • Subscribe

    U COMMENT
    I FOLLOW

    Subscribe in a reader

    OR

    Subscribe via e-mail

    Enter your email address: 

    Delivered by FeedBurner

     

  • Follow Me

    • Twitter
    • FaceBook
    • Digg
    • StumbleUpon
    • Propeller
    • Delicious
    • Plaxo

     

  • Recent Posts

    • ASUS Eee PC 1005HA-PU1X-BK Black Netbook
    • jQuery – Date Picker
    • Using VB.NET From CSharp
    • iTextSharp – Adding Images
    • Hungarian Notation – Use What Works, Spit Out The Bones
    • Pre Order Windows 7
    • jQuery Dialog – With Validation Controls
    • iTextSharp – The easy way
    • Structure of my ASP.NET Web Applications
    • 35% Off Accronis True Image 2009 Home
    • VB.NET Hide Module Name
    • ASP.NET/VB.NET – Video Training
    • Does jQuery Make Us Lazy?
    • PDFs Using iTextSharp
    • Programming SEO – Ping



  • Advertise on this site through Lake Quincy Media
  • DotNetNuke Sponsor

     

    Most Valuable Blogger
  • Sponsor

  • Categories

    • Advanced CSharp
    • Advanced VB.NET
    • ASP.NET MVC
    • Did you know
    • DotNetNuke – Module Development
    • DotNetNuke – Skinning
    • internationalization
    • iTextSharp
    • jQuery
    • none
    • Seach Engine Optimization
    • Silverlight
    • SQL For Programmers
    • Twitter
    • winforms
  • Cloud

    .net ajax architecture asp.net book books containers csharp css dal dataset datasets dotnetnuke events gridview images internationalization internet explorer javascript jQuery json linq listview modules ms-sql MVC objectdatasource programming reflection seo Silverlight skinning sql testing tsql tutorial Twitter twitterizer vb.net video view Vista visual studio webservice WordPress
  • Archives

    • July 2009
    • June 2009
    • May 2009
    • April 2009
    • March 2009
    • February 2009
    • January 2009
    • December 2008
    • November 2008
    • October 2008
    • September 2008
    • August 2008
    • July 2008
    • June 2008
    • May 2008
    • April 2008
    • March 2008
    • February 2008
    • January 2008
    • December 2007
    • November 2007
    • October 2007
  • Meta

    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org
    • Privacy Policy
  • Calendar

    September 2008
    S M T W T F S
    « Aug   Oct »
     123456
    78910111213
    14151617181920
    21222324252627
    282930  
  • Blogroll

    • Alvin Ashcraft’s Morning Dew
    • ASP.NET Consulting
    • Life Hacker
    • Remember Anything
    • The Price of Their Toys
    • Uncategorized Thought


.NET Answers © 2007 - 2008 All Rights Reserved.
Entries and Comments.