I would like to show a confirmation Box with the message when the user check the CheckBox.
So i have a GridView and there is a column for CheckBoxes.
So whenever user check the CheckBox i would like to show a confirmation box and when user click cancel on that box i would like to uncheck that CheckBox.
when user press OK then i would like to fire a standard asp.net CheckBox_CheckedChanged where i am doing some database work.
I dont know how to do that in javascript or Jquery.
I found it on google where there is only one CheckBox and you can use the ID and using the Jquery you can show the popup.
BUT i have a GridView and there are lots of CheckBoxes for each row.
Please suggest me some working example or Code.
Thanks
***** EDITS *******
here is the code i have got so far.
$('#gvOrders').click(function () {
var checked = $(this).is(':checked');
if (checked) {
document.getElementById("confirm_value").value = "Yes";
if (!confirm('Are you sure you want to mark this order as received?')) {
$(this).removeAttr('checked');
}
}
else {
document.getElementById("confirm_value").value = "No";
if (!confirm('Are you sure you want to mark this order as not received?')) {
$(this).removeAttr('checked');
}
});
This is not working so far when CheckBox checked. I am not sure what i am doing wrong here.
*** HTML FOR GRIDVIEW *******
<asp:GridView ID="gvOrders" runat="server" AutoGenerateColumns="false" CssClass="gvClickCollectOrders"
DataKeyNames="ac_OrderId" OnRowDataBound="gvOrders_RowDataBound" AllowPaging="true">
<Columns>
<asp:BoundField DataField="ac_OrderId" Visible="false" />
<asp:BoundField DataField="ac_OrderNumber" HeaderText="Order No" DataFormatString="WWW{0}" />
<asp:TemplateField HeaderText="Order Date">
<ItemTemplate>
<%# GetOrderDate(AlwaysConvert.ToInt(Eval("ac_OrderId"))) %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Customer Name">
<ItemTemplate>
<%# Eval("CustomerFirstName") %> <%# Eval("CustomerLastName") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Received In Store">
<ItemTemplate>
<asp:CheckBox ID="cbIsReceived" runat="server" AutoPostBack="true" Checked='<%# Eval("IsReceived") %>'
OnCheckedChanged="cbIsReceived_CheckedChanged"/>
<asp:Label ID="receivedDateText" Text="" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Collected By Customer">
<ItemTemplate>
<asp:CheckBox ID="cbIsCollected" runat="server" AutoPostBack="true" Checked='<%# Eval("IsCollected") %>'
OnCheckedChanged="cbIsCollected_CheckedChanged" />
<asp:Label ID="collectedDateText" Text="" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<asp:Label ID="emptyGrid" runat="server" Text="there are no Click and Collect orders placed for the selected store."
CssClass="emptyGridMessage"></asp:Label>
</EmptyDataTemplate>
</asp:GridView>
Using jQuery
Assign some class to your gridview checkbox and bind the event on that class.
Using javascript
You can bind the javascript event on check box and it will be applied to all generated checkboxes of each row of grid automatically.