Checking all CheckBoxes in a GridView

Scott Mitchell has written another fantastic article on the simple and clean implementation of providing the check/uncheck all functionality in the GridView control.

Link: Checking All CheckBoxes in a GridView

The only thing his implementation missing in the article is placing CheckBox in the header of the GridView, and using it to toggle rows CheckBoxes. I made a small modification to the existing code to add this feature:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    If Not Page.IsPostBack Then
        Dim dirInfo As New DirectoryInfo(Request.PhysicalApplicationPath)

        FileList.DataSource = dirInfo.GetFiles()
        FileList.DataBind()
    End If

    'On every page visit we need to build up the CheckBoxIDs array

    For Each gvr As GridViewRow In FileList.Rows
        'Get a programmatic reference to the CheckBox control

        Dim cb As CheckBox = CType(gvr.FindControl("RowLevelCheckBox"), CheckBox)

        ClientScript.RegisterArrayDeclaration("CheckBoxIDs", String.Concat("'", cb.ClientID, "'"))
    Next

    '--modified code

    Dim checkAll As New CheckBox()
    checkAll.Text = ""
    checkAll.ID = "checkAll"
    checkAll.Attributes.Add("onclick", "ChangeAllCheckBoxStates(this.checked);")
    FileList.HeaderRow.Cells(0).Controls.Add(checkAll)

End Sub

Guideline on Object Design

Alan has written a series of some good class design and implementation guidelines post. URL: Object Design and Implementation

Links:
Rule #1: Practice Drawing Make Good Classes
Rule #2: Documation!
Rule #3: Alan’s Class Template (“ACT”)
Rule #4: Never Walk, But Fly!!!
Rule #5: Always evaluate How We Fly!
Rule #6: No Private Variable Shall Have Direct Access to the Class Public Interface
Rule #7 & #8: All about Numbers!!

Snippet Compiler

Here is a useful .NET utility tool if you just want to do quick test your code and without requiring to launch VS.NET and creating a new project setup.

Snippet Compiler

Snippet Compiler

Link:
Snippet Compiler

Download:
2.0.8.3 for .NET 2.0 | 2.0.7.1 for .NET 1.1

  • It minimize to the system tray of task bar.
  • It can also builds WinForm EXEs, console EXEs or DLLs.
  • You can compile multiple C#, VB.NET ASP.NET code.
  • It can be used to store templates library as well.
  • IntelliSense for static members and method
  • You can also export your snippet in HTML format which can be post in your blog.

Automating Your Builds With NAnt

NAnt is a powerful scripting tool designed for developers, software process engineers, and build specialists to create an automated, repeatable process for building their developed application. NAnt provides powerful XML-based scripting and some really cool features, as Jean-Paul Boodhoo explains in his series of post “Automating Your Builds With NAnt”, which can streamline your development and unit testing effort dramatically.

Automating Your Builds With NAnt – Part 1
Automating Your Builds With NAnt – Part 2
Automating Your Builds With NAnt – Part 3
Automating Your Builds With NAnt – Part 4
Automating Your Builds With NAnt – Part 5
Automating Your Builds With NAnt – Part 6
Automating Your Builds With NAnt – Part 7