By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,569 Members | 1,321 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,569 IT Pros & Developers. It's quick & easy.

Problem with datagrid checkbox

P: n/a
Well, it seems as though every time I fix one problem I make yet another.

Anyhow, this is probably an easy one but I haven't found any answers
doing a search so I figured I would ask it here. I have a data grid
with check boxes in it, each check box called chkSelect. If I check
all the checkboxes and run through the code, the value of chkSelect =
false all the time, no matter what the state of the checkbox is.

Heres the code

Dim objItem As DataGridItem
Dim deleteme As Integer
For Each objItem In dgClients.Items
'Ignores the invalid items
If objItem.ItemType <> ListItemType.Header And _
objItem.ItemType <> ListItemType.Footer And _
objItem.ItemType <> ListItemType.Pager Then
'Then retrieve the value of the checkbox
Dim chkTest As CheckBox
Dim blnDelete As Boolean
blnDelete =
CType(objItem.Cells(0).FindControl("chkSelect"), CheckBox).Checked
chkTest = objItem.FindControl("chkSelect")

If blnDelete = True Then
deleteme = CInt(objItem.Cells(1).Text)
dbaddclient.DeleteClient(deleteme)
End If

End If
Next
Note that chkTest is in their just so I can see the state of the
checkbox in debug without the rest of the code getting in the way. It
always reads false.
Nov 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
are you by any chance binding the datagrid on post back..before you read all
checkboxes?
complete code of your aspx file will help us to probe the issue.

Av.
"CaptRR" <un*****@unknown.com> wrote in message
news:AJ********************@fyi.net...
Well, it seems as though every time I fix one problem I make yet another.

Anyhow, this is probably an easy one but I haven't found any answers doing
a search so I figured I would ask it here. I have a data grid with check
boxes in it, each check box called chkSelect. If I check all the
checkboxes and run through the code, the value of chkSelect = false all
the time, no matter what the state of the checkbox is.

Heres the code

Dim objItem As DataGridItem
Dim deleteme As Integer
For Each objItem In dgClients.Items
'Ignores the invalid items
If objItem.ItemType <> ListItemType.Header And _
objItem.ItemType <> ListItemType.Footer And _
objItem.ItemType <> ListItemType.Pager Then
'Then retrieve the value of the checkbox
Dim chkTest As CheckBox
Dim blnDelete As Boolean
blnDelete =
CType(objItem.Cells(0).FindControl("chkSelect"), CheckBox).Checked
chkTest = objItem.FindControl("chkSelect")

If blnDelete = True Then
deleteme = CInt(objItem.Cells(1).Text)
dbaddclient.DeleteClient(deleteme)
End If

End If
Next
Note that chkTest is in their just so I can see the state of the checkbox
in debug without the rest of the code getting in the way. It always reads
false.

Nov 18 '05 #2

P: n/a
Hi CaptRR,

I think Avnrao's suggestion about the rebinding in Page_Load event is
reasonable, would you please have a check on the page_load method or any
other place to see wehether the datagrid has been rebinded so that the
checkboxes' values be reset?
Also, if you still have no idea on this issue, I think you may provide the
whole page's source so that we can perform some tests on ourside to do some
further troubleshoot. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Nov 18 '05 #3

P: n/a
Yep

You two were right. Thats exactly what I. It was a function refilling
the datagrid every time the page loaded before I looked at the check boxes.

This also answered allot of questions about strange things that have
been happening. Up to this point I have been thinking of asp.net as
just another form of vb.net. So I didn't realize that page_load goes
off every time you hit a button. This was also the reason my last problem.

Once again thanks guy, I really do appreciate it. If y'all are ever in
Pittsburgh, I'll buy ya a beer :)

Steven Cheng[MSFT] wrote:
Hi CaptRR,

I think Avnrao's suggestion about the rebinding in Page_Load event is
reasonable, would you please have a check on the page_load method or any
other place to see wehether the datagrid has been rebinded so that the
checkboxes' values be reset?
Also, if you still have no idea on this issue, I think you may provide the
whole page's source so that we can perform some tests on ourside to do some
further troubleshoot. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #4

P: n/a
Hi CaptRR,

Thanks for the followup. Really glad that you've resolved the problem. And
here are some further resources maybe helpful to you on understanding the
ASP.NET's page model:

#The ASP.NET Page Object Model
http://msdn.microsoft.com/library/en...eobjectmodel.a
sp?frame=true

#Web Forms Page Processing
http://msdn.microsoft.com/library/en...msPageProcessi
ngStages.asp?frame=true

Enjoy your times!

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.