Navigation

Search

Categories

On this page

Using jQuery to Hide Table Rows in a Gridview
CSS Reference
Open Source Templates
CSS Style
CSS Tools and Links

Archive

Blogroll

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

RSS 2.0 | Atom 1.0 | CDF

Send mail to the author(s) E-mail

Total Posts: 240
This Year: 46
This Month: 3
This Week: 0
Comments: 0

Sign In
Pick a theme:

# Wednesday, September 09, 2009
Wednesday, September 09, 2009 4:26:55 PM (GMT Daylight Time, UTC+01:00) ( CSS | Gridview | jQuery )

 

I’m working on a project which requires users to have the ability to hide rows in a table associated with a certain value.  I checked around and using jQuery seemed to be the best option.   This is a much more elegant approach than doing it server-side.  Here’s what I did.

First, I included a hidden field as a row in my Gridview.  This field is a bit field (true/false) which two CSS classes and one of which is ‘hiddenField’ which makes the field invisible to the user.

<asp:boundfield DataField="InternalOnly" ShowHeader="true" ItemStyle-CssClass="hiddenField internalField" />

CSS code:

.hiddenField {    
    visibility:hidden;
}

Above the Gridview, I included a checkbox with an Id of chkInternal which the user can toggle to hide/show the rows in the Gridview

<input name="chkInternal" id="chkInternal" type="checkbox" />Exclude Non-product fields

Lastly, I use this bit of jQuery code to hide/show the rows in the table. When the chkInternal checkbox is checked, it applies the CSS property display: none to the the entire table row using the jQuery method .parent. It looks for the second CSS class property ‘internalField’. Conversely, when the checkbox chkInternal is not checked, the CSS property display: block is applied to the row making the row visible again. 

<script language="javascript" type="text/javascript">    
$(document).ready(function() {      
      $('#chkInternal').click(
          function() {
          $('.internalField').each(function() {
             if ($("#chkInternal").is(":checked"))
            {
                if ($(this).text() == "True") 
                        $(this).parent().css('display', 'none');                
            }
            else
            {      
                $(this).parent().css('display', 'block');                
            }
        });                 
    });                      
});
</script>
Comments [0] | | # 
# Tuesday, March 03, 2009
Tuesday, March 03, 2009 4:15:57 PM (GMT Standard Time, UTC+00:00) ( CSS )


I came across this amazing CSS reference on MSDN

http://msdn.microsoft.com/en-us/library/ms531205(vs.85).aspx

Comments [0] | | # 
# Monday, February 09, 2009
Monday, February 09, 2009 2:28:21 PM (GMT Standard Time, UTC+00:00) ( CSS | HTML )

 

A couple of sources for great, free Web templates for the design-challenged.

http://www.oswd.org/ 

http://www.opendesigns.org/

Comments [0] | | # 
# Monday, December 10, 2007
Monday, December 10, 2007 1:13:24 AM (GMT Standard Time, UTC+00:00) ( CSS | HTML )

 

This dumb post is just for my own reference.  This catch-all CSS references uses a font style that I like for all of the most common HTML page elements.

body, input, select, textarea, button {font-family:Verdana, sans-serif; font-size:x-small}
Comments [0] | | # 
# Monday, November 12, 2007
Monday, November 12, 2007 9:48:10 PM (GMT Standard Time, UTC+00:00) ( CSS )

Here are a few CSS tools and links that I came across that look useful

Comments [0] | | #