OnCheckedChanged event does not seem to execute (checkbox ingridview)


D

Danielle

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
 
Ad

Advertisements

M

Munna

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
 

Top