473,386 Members | 1,793 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Problem with datagrid checkbox

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
4 1189
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Job Lot | last post by:
I have an Expense Data Entry form which contains a DataGrid showing various expense categories. There are three columns Description, Cash Exp, Credit Exp, where Description column is readonly. ...
2
by: Mortel | last post by:
Hi, I have a DataGrid on my page. I show CheckBox in every row to select my rows and show one CheckBox in Title of that column to select all. I can use function and parameter id to read data and...
1
by: Joe Bloggs | last post by:
I am trying display the contents of a table in a web page, select certain rows from that table and then display the fields that I have selected (now table columns) as text in a Label object....
8
by: Inigo Jimenez | last post by:
I have an ASP .net web application installed in a Windows 2003 server. This web application has a webform that has a Datagrid. This Datagrid is filled with the data of a SQL table. I have a...
0
by: mike | last post by:
Hi there: I've read an excellent "how to"-article by Microsoft (no. 306227) - partly cited cited at the end of this email). I have implemented the code related to the part "How to Add a...
2
by: buran | last post by:
Dear ASP.NET Programmers, I have the following problem. I have a datagrid (ID: grdAllActions). This datagrid has two template columns: one column with the dropdownlist control (ID: ddlPS) and...
4
by: Mike | last post by:
Hi, Is there a possibility to have one of the Web Control Datagrid's column as a Calendar when editing data? Any resources on this subject? Thanks Mike
1
by: sianan | last post by:
I tried to use the following example, to add a checkbox column to a DataGrid in an ASP.NET application: http://www.codeproject.com/aspnet/datagridcheckbox.asp For some reason, I simply CAN'T get...
30
by: dbuchanan | last post by:
ComboBox databindng Problem == How the ComboBox is setup and used: My comboBox is populated by a lookup table. The ValueMember is the lookup table's Id and the DisplayMember is the text from a...
7
by: rn5a | last post by:
The first column of a DataGrid has a CheckBox for all the rows. I want that when users check a CheckBox, the BackColor of that entire row in the DataGrid should change to a different color. To...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.