Problem with datagrid checkbox

Discussion in 'ASP .Net' started by CaptRR, May 13, 2004.

  1. CaptRR

    CaptRR Guest

    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.
    CaptRR, May 13, 2004
    #1
    1. Advertising

  2. CaptRR

    avnrao Guest

    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" <> wrote in message
    news:...
    > 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.
    avnrao, May 13, 2004
    #2
    1. Advertising

  3. 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
    Steven Cheng[MSFT], May 13, 2004
    #3
  4. CaptRR

    CaptRR Guest

    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
    >
    >
    CaptRR, May 13, 2004
    #4
  5. 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-us/dnaspp/html/aspnet-pageobjectmodel.a
    sp?frame=true

    #Web Forms Page Processing
    http://msdn.microsoft.com/library/en-us/vbcon/html/vbconWebFormsPageProcessi
    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
    Steven Cheng[MSFT], May 14, 2004
    #5
    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. tshad
    Replies:
    0
    Views:
    513
    tshad
    Apr 15, 2005
  2. Vikram

    disable checkbox list checkbox

    Vikram, Jan 25, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    1,385
    ThunderMusic
    Jan 25, 2006
  3. =?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:
    809
    David Wier
    Oct 6, 2006
  4. Jason Huang
    Replies:
    0
    Views:
    546
    Jason Huang
    Jun 29, 2007
  5. Joey Pang
    Replies:
    4
    Views:
    510
    Joey Pang
    Jun 13, 2005
Loading...

Share This Page