CheckBox AutoPostBack=True

R

rn5a

I have a DataGrid where in the first column of each row is a CheckBox
(the CheckBoxes reside in the TemplateColumn of the DataGrid). The
CheckBox's AutoPostBack property is set to True & its CheckedChanged
event invokes a sub named 'CheckChanged'. The ID of the CheckBox in the
DataGrid is 'chk'. This is the sub 'CheckChanged':

Sub CheckChanged(ByVal obj As Object, ByVal ea As EventArgs)
Dim cbox As CheckBox
Dim dgiRow As DataGridItem

For Each dgiRow In dg1.Items
If (dgiRow.ItemType = ListItemType.Item Or dgiRow.ItemType =
ListItemType.AlternatingItem) Then
cbox = dgiRow.FindControl("chk")
If (cbox.Checked) Then
'doing something here
Else
Response.Write("hello<br>")
End If
End If
Next
End Sub

Assuming that the DataGrid has 10 rows, when I check one of the
CheckBoxes, then the text 'hello' appears 9 times...that's OK.... Next
I uncheck this checked CheckBox; the page gets posted but what I find
is the text 'hello' does not appear at all. Even if I add a
Response.Write("ABCD") line at the very top of the 'CheckChanged' sub
(i.e. it becomes the first line in the sub), then also when the only
checked CheckBox is unchecked & the page posts, the page doesn't
display the text 'ABCD" as well.

Why doesn't the sub 'CheckChanged' fire when the only checked CheckBox
is unchecked (which means that none of the CheckBoxes are checked in
the DataGrid)?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top