Problem with datagrid checkbox

C

CaptRR

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.
 
A

avnrao

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.
 
S

Steven Cheng[MSFT]

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
 
C

CaptRR

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 :)
 
S

Steven Cheng[MSFT]

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-us/dnaspp/html/aspnet-pageobjectmodel.a
sp?frame=true

#Web Forms Page Processing
http://msdn.microsoft.com/library/en-us/vbcon/html/vbconWebFormsPageProcessi
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
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top