Help with weird datagrid checkbox problem

AzureForge

New member
Joined
Dec 5, 2006
Messages
1
Programming Experience
1-3
I'm not sure if this is the correct area, forgive me if it is not!

I have this datagrid that is called deleteCourseGrid and it has a template column. I put a checkbox inside and its ID is deleteCheck.

I also have a confirm button that runs the code below.

The problem is, somehow, it does not detect that a box is checked. I tried checking each individual rows and cb.checked is always false.

Am I doing something wrong?

VB.NET:
        Dim connection As New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
        Dim command As New SqlCommand("delete from course where courseID = @courseID", connection)
        Dim i As Integer = 0
        Dim cb As CheckBox
        Dim courseID As String
        cb = deleteCourseGrid.Items(i).FindControl("deleteCheck")
        For i = 0 To deleteCourseGrid.Items.Count - 1
            If cb.Checked = True Then
                courseID = deleteCourseGrid.Items(i).Cells(0).Text
                command.Parameters.Add("@courseID", courseID)
                connection.Open()
                command.ExecuteNonQuery()
                connection.Close()
            End If
        Next
        Response.Redirect("updated.aspx")
 
You may want to do something like:



for each item as DataGridItem in me.deleteCourseGrid.Items
If item.ItemType = ListItemType.AlternatingItem OrElse item.ItemType = ListItemType.Item Then
cb = ctype(item.FindControl("deleteCheck"), CheckBox)​

if not isnothing(cb) then
if cb.Checked then
' do stuff
end if


end if


end if


next
 
Back
Top