Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Datagrid Control (http://www.velocityreviews.com/forums/f60-asp-net-datagrid-control.html)
-   -   checkbox column in a datagrid problem (http://www.velocityreviews.com/forums/t759159-checkbox-column-in-a-datagrid-problem.html)

Eric 07-16-2003 03:47 PM

checkbox column in a datagrid problem
 
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.






Peter Cresswell 07-16-2003 07:11 PM

Re: checkbox column in a datagrid problem
 
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

p-cresswell@iname.com

"Eric" <mcswaine@missouri.edu> wrote in message
news:e3TvvH7SDHA.2260@TK2MSFTNGP12.phx.gbl...
> 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.
>
>
>
>
>




Eric 07-16-2003 08:25 PM

Re: checkbox column in a datagrid problem
 
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" <p-cresswell@iname.com> wrote in message
news:%23T3QU48SDHA.3192@tk2msftngp13.phx.gbl...
> 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
>
> p-cresswell@iname.com
>





All times are GMT. The time now is 02:10 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.