By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,660 Members | 1,037 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,660 IT Pros & Developers. It's quick & easy.

OnCheckedChanged event does not seem to execute (checkbox ingridview)

P: n/a
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
Jun 27 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Jun 8, 1:31*am, Danielle <wxb...@aol.comwrote:
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
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.