3 Replies - 4864 Views - Last Post: 29 March 2011 - 04:12 AM Rate Topic: -----

#1 aks0124  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 24-March 11

Disabling the checkboxes in the gridview.

Posted 24 March 2011 - 05:49 AM

I have to disable the checkboxes in the Gridview on the basis of the TreeView node.if First 4 nodes without the chiled nodes is clicked then all the checkboxes to be disable(I used DisableAllCheckBoxes() method) ,if the nodes has the child node then some Checkboxes which are checked to disable(I used the DisableCheckBoxes())
I have tried the below code to disable the checkboxes in GRIDVIEW, all is working this code is not disabling the check box in last row.


protected void grdmain_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                HiddenField hdnStatus = (HiddenField)e.Row.FindControl("hdnStatus");
                HiddenField hdnModlid = (HiddenField)e.Row.FindControl("hdnModlid");
                HiddenField hdnFORMID = (HiddenField)e.Row.FindControl("hdnFORMID");

                if ((tvModule.Nodes[0].Selected == true) || (tvModule.Nodes[1].Selected == true) || (tvModule.Nodes[2].Selected == true) || (tvModule.Nodes[3].Selected == true) || (tvModule.Nodes[4].Selected == true) || (tvModule.Nodes[5].Selected == true))
                {
                    DisableAllCheckBoxes();
                }
                else
                {
                    if (HdnModIdMain.Value == hdnModlid.Value)
                    {
                        ((CheckBox)e.Row.FindControl("chkstatus")).Checked = true;
                        e.Row.BackColor = System.Drawing.Color.Beige;
                    }
                    else
                    {
                        ((CheckBox)e.Row.FindControl("chkstatus")).Checked = false;
                    }
                }
            }        
       
        DisableCheckBoxes();       
    }

    private void DisableCheckBoxes()
    {
        CheckBox chkbox;
        int rowCount = 0;
        rowCount = grdmain.Rows.Count;
        for (int i = 0; i <= rowCount - 1; i++)
        {
            chkbox = (CheckBox)grdmain.Rows[i].FindControl("chkstatus");
            if (chkbox.Checked)
                chkbox.Enabled = false;
        }
    }
    private void DisableAllCheckBoxes()
    {
        CheckBox chkbox;
        int rowCount = 0;
        rowCount = grdmain.Rows.Count;
        for (int i = 0; i <= rowCount - 1; i++)
        {
            chkbox = (CheckBox)grdmain.Rows[i].FindControl("chkstatus");
            chkbox.Enabled = false;

        }
    }


Is This A Good Question/Topic? 0
  • +

Replies To: Disabling the checkboxes in the gridview.

#2 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 441
  • View blog
  • Posts: 1,488
  • Joined: 28-April 09

Re: Disabling the checkboxes in the gridview.

Posted 24 March 2011 - 09:18 PM

well since you're disabling the checkboxes during the RowDataBound event you don't need to call do a disable all checkboxes type of event, you just need to disable the checkbox for that row. You are essentially looping through that code to disable all checkboxes for every row of the GridView. If you have 10 rows then you're actually disabling all 10 checkboxes (1 for each row) 10 times, once for each row. You'd be basically disabling 100 checkboxes instead of just 10.


you should be able to just do something like

if (tvModule.Nodes[0].Selected 
    || tvModule.Nodes[1].Selected 
    || tvModule.Nodes[2].Selected 
    || tvModule.Nodes[3].Selected 
    || tvModule.Nodes[4].Selected 
    || tvModule.Nodes[5].Selected)
{
    (e.Row.FindControl("chkstatus") as CheckBox).Enabled = false;
}



And it will disable each row as they are data bound

This post has been edited by Nakor: 24 March 2011 - 09:20 PM

Was This Post Helpful? 0
  • +
  • -

#3 marinus  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 135
  • View blog
  • Posts: 575
  • Joined: 14-April 10

Re: Disabling the checkboxes in the gridview.

Posted 25 March 2011 - 03:42 PM

What happend when you modify you loop to this ?

for (int i = 0; i < rowCount; i++)

Was This Post Helpful? 1
  • +
  • -

#4 aks0124  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 24-March 11

Re: Disabling the checkboxes in the gridview.

Posted 29 March 2011 - 04:12 AM

View PostNakor, on 24 March 2011 - 09:18 PM, said:

well since you're disabling the checkboxes during the RowDataBound event you don't need to call do a disable all checkboxes type of event, you just need to disable the checkbox for that row. You are essentially looping through that code to disable all checkboxes for every row of the GridView. If you have 10 rows then you're actually disabling all 10 checkboxes (1 for each row) 10 times, once for each row. You'd be basically disabling 100 checkboxes instead of just 10.


you should be able to just do something like

if (tvModule.Nodes[0].Selected 
    || tvModule.Nodes[1].Selected 
    || tvModule.Nodes[2].Selected 
    || tvModule.Nodes[3].Selected 
    || tvModule.Nodes[4].Selected 
    || tvModule.Nodes[5].Selected)
{
    (e.Row.FindControl("chkstatus") as CheckBox).Enabled = false;
}



And it will disable each row as they are data bound

Thanks for the support the issue has been resolved now.

This post has been edited by aks0124: 29 March 2011 - 04:12 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1