checkbox column in a datagrid problem

E

Eric

I have a checkbox column in a datagrid so a user can select (by checking)
mulitple items then hit a submit button to add them. The problem is that I
try to evaluate (xxx.checked = true) but it is always equal to false.
The checkbox column appears to have no clue that a box is indeed checked.
I've set breakpoints and watched i =
(however many units) a thousand times. But chkADD.checked NEVER equals true
even though I now the item is checked.
Here is the code for the sub:

Sub AddBooksChecked()
Dim CProdVB As IMN.Data.CustomProductsDB = New
IMN.Data.CustomProductsDB()
Dim iBookID As Integer = CInt(ViewState("iBookID"))
' Iterate through all rows within the list
Dim i As Integer
Dim iCounter As Integer = 0

For i = 0 To CProductgrid.Items.Count - 1
' Obtain references to row's controls
Dim chkADD As CheckBox =
CType(CProductgrid.Items(i).FindControl("AddMe"), CheckBox)
Try

If chkADD.Checked = True Then 'this at the moment is
NEVER true

iCounter = iCounter + 1
Dim lblDocID As Label =
CType(CProductgrid.Items(i).FindControl("DocID"), Label)
CProdVB.AddTOCItem(iBookID, lblDocID.Text)
End If
Catch
MyMsg.Text = "There has been a problem with one
or more of your inputs."
Finally
MyMsg.Text = iCounter & " documents were added
to your open book."
End Try
Next
MyMsg.Visible = True
End Sub

If anyone could give some directions on where to look for the problem, it
would be greatly appreciated.
 
P

Peter Cresswell

Check that the datagrid isn't being re-binded on each postback.
I expect it might be re-binding before the you evaluating code is run.

Not a VB man, but in C# I'd check that my databinding is only done on the
first load of a page by:
private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
//Code to bind my datagrid
}
}


Hope this helps,



Peter Cresswell

(e-mail address removed)
 
E

Eric

Thanks alot. That was exactly what it was. It was being re-binded each
postback. I forgot to add "If not Page.IsPostBack blah blah" to the
Page_Load sub.
Thanks again
 

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,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top