This is a migrated thread and some comments may be shown as answers.

client select column

1 Answer 67 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Naresh
Top achievements
Rank 1
Naresh asked on 26 May 2011, 11:07 AM
Hi team,
usually the client select column select all the checkboxes in the grid , but what i want is when i click the checkbox in the header of the gird
i want to check only the checkboxes that are enabled in the grids.Please provide the code snippet to acheive this.

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 26 May 2011, 01:00 PM
Hello Naresh,

Try the following to achieve your requirement.
C#:
protected void grdEmail_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridHeaderItem)
        {
            GridHeaderItem Hitem = (GridHeaderItem)e.Item;
            CheckBox chk = (CheckBox)Hitem["ClientColumnUniqueName"].Controls[0];
            chk.Attributes.Add("onclick", "change();");
        }
        if (e.Item is GridDataItem)
        {
         GridDataItem item = (GridDataItem)e.Item;
          if(item["FirstName"].Text=="king")//based on some condition
          {
            CheckBox chk = (CheckBox)item["ClientColumnUniqueName"].Controls[0];
            chk.Enabled = false;
          }
        }
    }

Javascript:
function change()
 {
   var masterTable = $find("<%= grdEmail.ClientID %>").get_masterTableView();
   for (var index = 0; index < masterTable.get_dataItems().length; index++)
     {
            var row = masterTable.get_dataItems()[index]; ;
            var cell = masterTable.getCellByColumnUniqueName(row, "ClientColumnUniqueName");
            var chk = cell.getElementsByTagName("input")[0];
            if (chk.disabled)
            {
                chk.checked = false;
            }
            else
            {
                chk.checked = true;
            }
        }
 }

Hope it helps.

Thanks,
Princy.
Tags
Grid
Asked by
Naresh
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or