Click here to Skip to main content
13,452,206 members (56,304 online)
Rate this:
Please Sign up or sign in to vote.
I have a grid in which I have 7 columns where all the checkboxes are disabled. How do I disable the delete button?

In the diagram below, if all the checkboxes in the Cancel SO Line Item column are disabled then the DEL button should be disabled.

What I have tried:

<asp:TemplateField HeaderText="Cancel SO Line Item">
        <asp:checkbox ID="cbSOCan" runat="server" ViewStateMode="Enabled" EnableViewState="true"></asp:checkbox>

     <asp:LinkButton CssClass="btn btn-primary" ID="btnCancelItem" runat="server" CausesValidation="False"OnClientClick="return Confirmationbox();"> Cancel Item</asp:LinkButton>
 <asp:HiddenField id="hdnval" value=0 runat="server"/>

c# code
protected void btnCancelItem_Click(object sender, EventArgs e)
    foreach (GridViewRow gvrow in gvPOItems.Rows) {
        CheckBox chkdelte = (CheckBox)gvrow.FindControl("cbSOCan");
        HiddenField hdnval = (HiddenField)gvrow.FindControl("hdnval");
        if (chkdelte.Checked) {
            // gvAdditionalArea.Rows(rowIndex).Cells(0).Text()
            Int32 ItemNumber = Convert.ToInt32(gvrow.Cells(0).Text());
            Queries.CancelSOlineItem(ItemNumber, txtPONumber.Text);
            gvrow.Cells(7).Text() = "Cancelled";
            chkdelte.Checked = false;
            chkdelte.Enabled = false;
            hdnval.Value = 1;
protected void Page_Load(object sender, EventArgs e)
{if (!IsPostBack)
int rowcount = 0;
foreach (GridViewRow gvrow in gvPOItems.Rows) {
    HiddenField hdnval = (HiddenField)gvrow.FindControl("hdnval");
    if ((hdnval.Value == 1)) {
        rowcount = rowcount + 1;
if ((gvPOItems.Rows.Count == rowcount)) {
    btnCancelItem.Visible = false;
Posted 19-May-17 5:57am
Updated 21-May-17 4:40am
Rate this: bad
Please Sign up or sign in to vote.

Solution 3[^]

Go through the above link, make small necessary changes in code like.

function chkRowClicked() {
             var unChkCount = 0, ChkCount = 0;
             ChkCount = $('.clsChkRow:checkbox:checked').length;
             unChkCount = $('.clsChkRow:checkbox:not(:checked)').length;
             if (ChkCount == 0) {
                 $("#btnId").prop('disabled', 'false');
             else if (unChkCount == 0) {
                 $("#btnId").prop('disabled', 'true');
Deepak Jain 21-May-17 6:22am
but how to do it on page load ?
sameer549 21-May-17 7:11am
register pageload script from codebehind and call your javascript function
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

Instead of registering from code behind. I suggest you use onload method of JS
        window.onload = function () {
 $(":checkbox").on("click", function(){

// your work

} );


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.180318.3 | Last Updated 21 May 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100