Add Grid View Like this
<asp:GridView ID="GVID">
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="QchkBxSelect" runat="server" />
</ItemTemplate>
<HeaderTemplate>
<asp:CheckBox ID="QchkBxHeader" onclick="javascript:QHeaderClick(this);" runat="server" />
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Risk ID" meta:resourcekey="asptempriskid">
<ItemTemplate>
<asp:Label ID="lbluniqueId" Text='<%# Eval("uniqueID") %>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Call The Java Script to Select DeSelect Checkbox
<script type="text/javascript">
var QTotalChkBx;
var QCounter;
window.onload = function () {
QTotalChkBx = parseInt('<%= this.GVID.Rows.Count %>');
QCounter = 0;
}
function QHeaderClick(QCheckBox) {
var QTargetBaseControl =
document.getElementById('<%= this.GVID.ClientID %>');
var QTargetChildControl = "QchkBxSelect";
var QInputs = QTargetBaseControl.getElementsByTagName("input");
for (var n = 0; n < QInputs.length; ++n)
if (QInputs[n].type == 'checkbox' &&
QInputs[n].id.indexOf(QTargetChildControl, 0) >= 0)
QInputs[n].checked = QCheckBox.checked;
QCounter = QCheckBox.checked ? QTotalChkBx : 0;
}
function QChildClick(QCheckBox, QHCheckBox) {
var QHeaderCheckBox = document.getElementById(QHCheckBox);
if (QCheckBox.checked && QCounter < QTotalChkBx)
QCounter++;
else if (QCounter > 0)
QCounter--;
if (QCounter < QTotalChkBx)
QHeaderCheckBox.checked = false;
else if (QCounter == QTotalChkBx)
QHeaderCheckBox.checked = true;
}
</script>
add Asp Button Outside Grid View Like this
<asp:Button ID="Delete" runat="server" Text="Delete "
OnClick="Delete_Click" />
Try this below Code In Delete Button onClick Event
string flagchecked = "0";
ArrayList arrrid = new ArrayList();
// Select the checkboxes from the GridView control
for (int i = 0; i < GVID.Rows.Count; i++)
{
GridViewRow row = GVID.Rows[i];
bool isChecked = ((CheckBox)row.FindControl("chkBxSelect")).Checked;
if (isChecked)
{
flagchecked = "1";
string uniqueid= ((Label)row.FindControl("lblitemuniqueId")).Text;
arrrid.Add(uniqueid);
}
}
if (flagchecked == "1")
{
for (int jR = 0; jR < arrrid.Count; jR++)
{
//Delete Operation
}
}