Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
55
Checkboxes in one Row of a WebGrid
posted

Hello,

I have a grid that has columns of data. The first row of each column is a boolean. I would like to display that row as checkboxes to permit a user to check or uncheck that particular box.

 

Help!

Thanks,

Michael

Parents
No Data
Reply
  • 4555
    Suggested Answer
    posted

    I am attaching a sample that does a similar functionality, with the check boxes displayed in the header.

    In the sample provided I am creatimg to templated columns and assigning checkboxes at the header. In the InitilaizeLayout event I am checking/unchecking the CheckBoxes at the header according to the values in the first row using the following code snippet:


         if (e.Row.Index == 0)
            {
                e.Row.Hidden = true;


                foreach (UltraGridCell cell in e.Row.Cells)
                {
                    TemplatedColumn tc = cell.Column as TemplatedColumn;
                    HeaderItem item = tc.HeaderItem as HeaderItem;
                    CheckBox checkbox1 = item.Controls[1] as CheckBox;


                    checkbox1.Checked = ((int) cell.Value) != 0;
                }
       


                
           
            }

     

     

    On the client side I attached an event when the checkbox is fired.  First I check the column that was checked, and I get the first row in the Grid and I assign it the value using the following code snippet:


    function HeaderCheckedChanged(sender){
        var grid = igtbl_getGridById("<%= UltraWebGrid1.ClientID %>");
        var column = igtbl_getColumnById(sender.parentElement.id);


        if (column == null)
        {
            alert("Debugging: Column is null");
            return;
        }
       
       var index = column.Index;
       
       
        myrow = gridID.Rows.getRow(0);
    var cell_value = myrow.getCell(index).getValue();


    if((cell_value) == 0)
             {
              myrow.getCell(index).setValue(1);
              }
        else
              myrow.getCell(index).setValue(0);     
             
       

     

    }

     

    Magued

    Web_Templated_Chkbox_head.zip
Children
No Data