Hi, this is my first post on this thread.

I have a datagrid with a checkbox. I followed the one on msdna2 site using a tablestyle etc.

However, i want to do update using all the ones the user has checked.

I can do this for one single checked item and i can get the value that i require, but i am unsure of how to get all the checked items.

I am unsure of what to write for the for loop.

Any ideas. Mine is almost the same as the msdna.

Private Sub BoolCellClicked(ByVal sender As Object, ByVal e As BoolValueChangedEventArgs)
'Console.WriteLine("BoolCellClicked")
Me.DataGrid1.EndEdit(Me.DataGrid1.TableStyles(0).GridColumnStyles("Discontinued"), e.Row, False)
RefreshRow(e.Row)
Me.DataGrid1.BeginEdit(Me.DataGrid1.TableStyles(0).GridColumnStyles("Discontinued"), e.Row)
End Sub
Private Sub FormatGridRow(ByVal sender As Object, ByVal e As DataGridFormatCellEventArgs)
' Conditionally set properties in e depending upon e.Row and e.Col.
Dim discontinued As Boolean = CBool(IIf(e.Column <> 0, Me.DataGrid1(e.Row, 0), e.CurrentCellValue)) 'TODO: For performance reasons this should be changed to nested IF statements
' Check if discontinued?
If e.Column > 0 AndAlso CBool(Me.DataGrid1(e.Row, 0)) Then 'discontinued?
e.BackBrush = Me.disabledBackBrush
e.ForeBrush = Me.disabledTextBrush
ElseIf e.Column > 0 AndAlso e.Row = Me.DataGrid1.CurrentRowIndex Then 'currentrow?
e.BackBrush = Me.currentRowBackBrush
e.TextFont = Me.currentRowFont
End If
End Sub

Just have a button on the page. For the button click event handler have something like:

For Each item As DataGridItem In DataGrid1.Items
            Dim checkbox As CheckBox = CType(item.FindControl("<your checkbox id here>"), CheckBox)

            If checkbox.Checked Then
                string data = item.Cells(1).Text 
                'Do something useful
            End If
        Next

I use c# exclusivley so I struggled with the syntax, gosh I'd forgotten how wordy VB was!!

Hi, thanks for the reply.

Vb doesn't seem to like this line

For Each item As DataGridItem In DataGrid1.Item

I know that asp.net can do that, but vb.net doesn't seem to like it.

Any ideas?


I know that asp.net can do that, but vb.net doesn't seem to like it.

Any ideas?

There should be a space between For and Each both VB and C# support for each. There is a space in my posted code did you not cut and paste ? and it must work because I ran it succesfully on my PC and my post is a direct cut and paste from VS 2005.

That's ok, i managed to do it.

I assigned the source to a datatable and then checked for the change.

something like this

dim x as integer
dim dt as datatable
 
for x = 0 to dt.rows.count
 if dt.rows(e).item("checked") = false then
   do what i need to
end if
next
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.