checkbox column in a datagrid problem

Discussion in 'ASP .Net Datagrid Control' started by Eric, Jul 16, 2003.

  1. Eric

    Eric Guest

    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, Jul 16, 2003
    #1
    1. Advertising

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



    "Eric" <> wrote in message
    news:...
    > 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, Jul 16, 2003
    #2
    1. Advertising

  3. Eric

    Eric Guest

    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" <> wrote in message
    news:%...
    > 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
    >
    >
    >
     
    Eric, Jul 16, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ryan Lafferty

    DataGrid control with checkbox template column

    Ryan Lafferty, Aug 8, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    3,308
    Ryan Lafferty
    Aug 8, 2005
  2. =?Utf-8?B?RG90TmV0RGV2?=

    DataGrid and embeded Checkbox..How to find if checkbox clicked

    =?Utf-8?B?RG90TmV0RGV2?=, Oct 6, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    857
    David Wier
    Oct 6, 2006
  3. Gregory Rampton

    Convert an MS Access Yes/No column to a checkbox column in C# datagrid

    Gregory Rampton, Aug 6, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    226
    Gregory Rampton
    Aug 6, 2003
  4. Norman Katz

    web Datagrid checkbox column postback problem

    Norman Katz, Oct 15, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    464
    Norman Katz
    Oct 15, 2004
  5. Joey Pang
    Replies:
    4
    Views:
    549
    Joey Pang
    Jun 13, 2005
Loading...

Share This Page