I have a Gridview with checkbox and a delete button outside the GV,if a user directly clicks the Delete button then a error message Pops up.This works fine but the same doesnt works when the Delete button is placed in the Footer of the GV.
The Jquery that i have used is
$(document).ready(function () {
$("#btnDelete").click(function () {
var rowsSelected = $("#grdDailyReport input[name$='cbDelete']:checked").length;
if (rowsSelected == 0) {
alert('No rows selected');
return false;
}
else
return confirm(rowsSelected + ' row(s) will be deleted');
});
});
GV design
<asp:GridView ID="grdDailyReport" runat="server" AutoGenerateColumns="False" DataKeyNames="Id"
CurrentSortField="Id" CurrentSortDirection="ASC" AllowSorting="True"
ShowFooter="True" PageSize="5"
onpageindexchanging="grdDailyReport_PageIndexChanging" AllowPaging="True">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="cbDeleteHeader" runat="server" onclick = "checkAll(this);"/>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="cbDelete" runat="server" onclick = "Check_Click(this)"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Id" InsertVisible="False" SortExpression="Id">
<EditItemTemplate>
<asp:Label ID="lblID" runat="server" Text='<%# Eval("Id") %>'>
</asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblID2" runat="server" Text='<%# Bind("Id") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<EditItemTemplate>
<asp:LinkButton ID="lnkUpdate" runat="server" CommandArgument='<%# Eval("Id") %>' CommandName="UpdateRow">Update</asp:LinkButton>
<asp:LinkButton ID="lnkCancel" runat="server" CommandArgument='<%# Eval("Id") %>' CommandName="CancelRow">Cancel</asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="lnkEdit" runat="server" CommandArgument='<%# Eval("Id") %>' CommandName="EditRow">Edit</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView><br />
<asp:Button ID="btnDelete" runat="server" Text="Delete" OnClick="btnDelete_Click" />
GV with Footer template
<FooterTemplate>
<asp:Button ID="btnFooter" runat="server" Text="Delete"/>
</FooterTemplate>
Have changed the button ids in the Jquery with both the approach.It doent works with the 2nd approach.