Skip to main content
Email Password   helpLost your password?

Sample Image - checkBoxGrid.jpg

Introduction

This simple demo project shows, how you can add CheckBoxes to the DataGrid web control. This article shows handling automatic selection and getting the selected CheckBoxes, too.

Select all / Deselect all items

This simple method iterates through the grid and sets the Checked state of the CheckBoxes in the grid. And sets the Button's Caption to + / -.

 Private Sub selectAll()
        Dim oDataGridItem As DataGridItem
        Dim chkExport As System.Web.UI.WebControls.CheckBox

        If cmdSelectAll.Text = "+" Then
            For Each oDataGridItem In dgMain.Items

                chkExport = oDataGridItem.FindControl("chkExport")
                chkExport.Checked = True
            Next

            cmdSelectAll.Text = "-"
        Else
            For Each oDataGridItem In dgMain.Items
                chkExport = oDataGridItem.FindControl("chkExport")
                chkExport.Checked = False
            Next
            cmdSelectAll.Text = "+"
        End If
    End Sub

Find selected Items

This method iterate through the grid items, and adds the selected rows to an array.

    Private Sub cmdFindSelected_Click(ByVal sender As _
                       System.Object, ByVal e As System.EventArgs) _
                       Handles cmdFindSelected.Click

        Dim oDataGridItem As DataGridItem
        Dim chkExport As System.Web.UI.WebControls.CheckBox
        Dim oExArgs As New System.Collections.ArrayList()
        Dim sID As String
        
        For Each oDataGridItem In dgMain.Items

            chkExport = oDataGridItem.FindControl("chkExport")
            If chkExport.Checked Then
                sID = _
                  CType(oDataGridItem.FindControl("lblColumn"), Label).Text
                oExArgs.Add(sID)
            End If
        Next

    End Sub
You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralThanks for a clear example how to do this using VB.Net for an ASPX Web Page... Pin
Destiny777
13:27 22 May '08  
GeneralcmdFindSelected_Click Pin
Kathy 9999
7:47 1 Aug '05  
Generaldatagrid Pin
praveen saini
6:42 7 Mar '05  
GeneralRe: datagrid Pin
YetAnotherGr8Guy
23:38 22 Nov '05  
Generalprogressbar datagrid Pin
Anonymous
0:25 3 Jun '04  
GeneralClient Side Action for select All Pin
Akram Kayani
21:44 18 Sep '03  
Generalcounterpoint Pin
Shaun Wilde
11:35 16 Dec '02  
GeneralA couple suggestions Pin
Marc Clifton
14:52 15 Dec '02  
GeneralRe: A couple suggestions Pin
David Stone
20:03 15 Dec '02  
GeneralRe: A couple suggestions Pin
Marc Clifton
1:32 16 Dec '02  


Last Updated 14 Dec 2002 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009