This is a migrated thread and some comments may be shown as answers.

Count Checked Rows

1 Answer 13 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Cush
Top achievements
Rank 1
Cush asked on 29 Jun 2011, 05:38 PM
Hi All

I was looking for a way to loop the entire grid and count all checked fields,
i came up with the following fucntion and i thought i would post it here in case anyone could use it.

Regards

Cush

Private Function Get_CountGridCheckBox(ByVal SelGrid As RadGrid, ByVal ColName As String, ByVal ChkBoxVal As Boolean) As Integer
        Dim RtnVal As Integer
        Dim currentPageIndex As Integer = SelGrid.CurrentPageIndex
        'Set initial value to zero
        RtnVal = 0
  
        For i As Integer = 0 To SelGrid.PageCount - 1
  
            ' Loop current page and count check box values
  
            For Each item As GridDataItem In SelGrid.Items
                Dim CheckBx As CheckBox = DirectCast(item(ColName).Controls(0), CheckBox)
                Dim CheckBxVal As Boolean = CheckBx.Checked
  
                If CheckBxVal = ChkBoxVal Then
                    RtnVal += 1
                End If
  
            Next
  
  
            ' Go to next Grid page
            currentPageIndex += 1
            If currentPageIndex >= SelGrid.PageCount Then
                currentPageIndex = 0
            End If
  
            SelGrid.CurrentPageIndex = currentPageIndex
            SelGrid.Rebind()
  
        Next
  
        'Return Result
        Return RtnVal
    End Function

1 Answer, 1 is accepted

Sort by
0
Genti
Telerik team
answered on 01 Jul 2011, 03:45 PM
Hi Cush,

Thank you for the contribution.

There are also some other DEMOS and HELP topics offered by Telerik that one can make use of.

*A little remark in this case would be to reference or find the controls by their ids.
For example it is more convenient to use:
dataItem.FindControl("CheckBox1") 
then
dataitem(ColName).Controls(0), CheckBox)

Kind regards,
Genti
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Cush
Top achievements
Rank 1
Answers by
Genti
Telerik team
Share this question
or