Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > checkbox column in a datagrid problem

Reply
Thread Tools

checkbox column in a datagrid problem

 
 
Eric
Guest
Posts: n/a
 
      07-16-2003
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.





 
Reply With Quote
 
 
 
 
Peter Cresswell
Guest
Posts: n/a
 
      07-16-2003
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

http://www.velocityreviews.com/forums/(E-Mail Removed)

"Eric" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>
>
>
>
>



 
Reply With Quote
 
 
 
 
Eric
Guest
Posts: n/a
 
      07-16-2003
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


"Peter Cresswell" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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 Removed)
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGrid and embeded Checkbox..How to find if checkbox clicked =?Utf-8?B?RG90TmV0RGV2?= ASP .Net 1 10-06-2006 04:11 PM
bind a dropdown in a column in a datagrid based on the dropdown value selected in another column of the datagrid. vishnu ASP .Net 1 03-25-2006 01:24 PM
how do i access a dropdownlists selected value in a datagrid edititemtemplate column from the selectedindexchanged event of another dropdownlist in a datagrid edititemtemplate column Dave M ASP .Net Datagrid Control 0 12-14-2004 11:53 AM
web Datagrid checkbox column postback problem Norman Katz ASP .Net Datagrid Control 0 10-15-2004 10:28 PM
Convert an MS Access Yes/No column to a checkbox column in C# datagrid Gregory Rampton ASP .Net Datagrid Control 0 08-06-2003 04:09 PM



Advertisments