OnCheckedChanged event does not seem to execute (checkbox ingridview)

Discussion in 'ASP .Net' started by Danielle, Jun 7, 2008.

  1. Danielle

    Danielle Guest

    Greetings all and thanks in advance for any help you can provide.

    I am trying ultimately to get values from a gridview row when a
    checkbox on the row is checked. the problem I'm having is that after
    ticking the checkbox, the whole page refreshes (expectedly), the
    checkbox is unmarked and the response.write message displayed below
    never displays. It follows that if I uncomment the lines that try to
    capture the value in cell(3) and display that variable nothing is
    displayed.


    The gridview is standard issue so I've included only the
    TemplateField
    for the checkbox:


    <asp:TemplateField >
    <ItemTemplate>
    <asp:CheckBox ID="chkContactSelect"
    runat="server"
    AutoPostBack="true"


    OnCheckedChanged="chkContactSelect_CheckedChanged" />
    </ItemTemplate>
    </asp:TemplateField>


    Here's the code for the sub:


    Protected Sub chkContactSelect_CheckedChanged(ByVal sender As
    Object, ByVal e As System.EventArgs)


    Dim selectedCheckbox As CheckBox
    selectedCheckbox = CType(sender, CheckBox)


    Dim selectedRow As GridViewRow
    selectedRow = CType(selectedCheckbox.NamingContainer,
    GridViewRow)


    If selectedCheckbox.Checked = True Then
    'Text = selectedRow.Cells(3).Text
    'Response.Write(Text)
    Response.Write("test")
    End If


    End Sub


    Thanks again for any help-
    Danielle
    Danielle, Jun 7, 2008
    #1
    1. Advertising

  2. Danielle

    Munna Guest

    On Jun 8, 1:31 am, Danielle <> wrote:
    > Greetings all and thanks in advance for any help you can provide.
    >
    > I am trying ultimately to get values from a gridview row when a
    > checkbox on the row is checked.  the problem I'm having is that after
    > ticking the checkbox, the whole page refreshes (expectedly), the
    > checkbox is unmarked and the response.write message displayed below
    > never displays.  It follows that if I uncomment the lines that try to
    > capture the value in cell(3) and display that variable nothing is
    > displayed.
    >
    > The gridview is standard issue so I've included only the
    > TemplateField
    > for the checkbox:
    >
    > <asp:TemplateField >
    >                     <ItemTemplate>
    >                         <asp:CheckBox ID="chkContactSelect"
    > runat="server"
    >                         AutoPostBack="true"
    >
    > OnCheckedChanged="chkContactSelect_CheckedChanged" />
    >                     </ItemTemplate>
    >                 </asp:TemplateField>
    >
    > Here's the code for the sub:
    >
    >     Protected Sub chkContactSelect_CheckedChanged(ByVal sender As
    > Object, ByVal e As System.EventArgs)
    >
    >         Dim selectedCheckbox As CheckBox
    >         selectedCheckbox = CType(sender, CheckBox)
    >
    >         Dim selectedRow As GridViewRow
    >         selectedRow = CType(selectedCheckbox.NamingContainer,
    > GridViewRow)
    >
    >         If selectedCheckbox.Checked = True Then
    >             'Text = selectedRow.Cells(3).Text
    >             'Response.Write(Text)
    >             Response.Write("test")
    >         End If
    >
    >     End Sub
    >
    > Thanks again for any help-
    > Danielle


    Hi Daniell

    Rather than subscribing checkbox's on check event...

    assign the checkbox a commandname and subscribe the item command event
    of gridview...

    when user click on checkbox it will fire the grids item command ... by
    traping the commandname do your work

    Best of luck

    Munna
    www.munna.shatkotha.com
    www.munna.shatkotha.com/blog
    www.shatkotha.com
    Munna, Jun 8, 2008
    #2
    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. Homa
    Replies:
    3
    Views:
    14,827
    nchavan
    Jul 23, 2009
  2. Maziar Aflatoun

    asp checkbox checking for OnCheckedChanged value

    Maziar Aflatoun, Sep 5, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    23,200
    radu_m
    Dec 29, 2008
  3. ethem
    Replies:
    1
    Views:
    1,180
    Ashok Kunwar Singh
    Mar 2, 2011
  4. arby

    Checkbox in DataGrid Not Firing OnCheckedChanged events.

    arby, Jan 30, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    504
    Alvin Bruney [MVP]
    Jan 31, 2004
  5. Hitesh Jain

    oncheckedchanged event is not firing everytime on checkbox

    Hitesh Jain, Oct 14, 2004, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    1,418
    Robert Koritnik
    Oct 15, 2004
Loading...

Share This Page