GeekArticles
Database
SQL Server
Database
SQL ServerChecking All Checkboxes in a GridView Using jQuery
<p>
In May 2006 I wrote two articles that showed how to add a column of checkboxes to a GridView and offer the ability for users to check (or uncheck) all checkboxes in
the column with a single click of the mouse. The first article, <a All CheckBoxes in a GridView</a>,
showed how to add and buttons to the page above the GridView that, when clicked, checked or unchecked all of the checkboxes. The second article,
<a All CheckBoxes in a GridView Using Client-Side Script and a Check All CheckBox</a>, detailed how
to add a checkbox to the checkbox column in the header row that would check or uncheck all checkboxes in the column. Both articles showed how to implement such
functionality on the client-side, thereby removing the need for a postback.
</p><p>
The JavaScript presented in these two previous articles still works, but the techniques used are a bit antiquated and hamfisted given the advances made in JavaScript
programming over the past few years. For instance, the script presented in the previous articles uses server-side code in the <code>DataBound</code> event
handler to assign a client-side <code>onclick</code> event handler to each checkbox. While this works, it violates the tenets of <a which is a design guideline for JavaScript programming that encourages a clean separation of functionality from presentation. (Ideally, event handlers
for HTML elements are defined in script.) Also, the quantity of JavaScript used in the two previous articles is quite hefty compared to the amount of code that would
be needed using modern JavaScript libraries like <a article presents updated JavaScript for checking (and unchecking) all checkboxes within a GridView. The two examples from the previous articles - checking/unchecking
all checkboxes using a button and checking/unchecking all checkboxes using a checkbox in the header row - are reimplemented here using jQuery and unobtrusive
JavaScript techniques. Read on to learn more!
<br /><a More ></a></p>
Sponsored Links
Read Next: Displaying a Grid of Data in ASP.NET MVC
Related Topics
Subscribe via RSS
SQL Server
- Naming Database Objects: Part II
- Trace Messages Part V: Trace Cleanup
- Naming Database Objects: Part I
- Multiple-Child Aggregation
- Creating SQL Tables for an Integrating Application Using Dexterity
- SQL Server 2005 Beta 2 Transact-SQL Enhancements
- .NET Rocks! - Brian Larson on SQL Server Reporting Services
- Computing the Trimmed Mean in SQL
- SQL Server 2000 Gains on Oracle
- Separator First Formatting (SFF)
