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
105
Checkbox column and checkbox in column header in ultrawebgrid
posted

Hi,

I have created a templated column and a templated column header. Here is the code snippet:

   <igtbl:ultrawebgrid>
   <Bands>
    <igtbl:UltraGridBand key="ugb1">
     <Columns>
      <igtbl:TemplatedColumn Key="check" Type="CheckBox" AllowUpdate="Yes">
             <HeaderTemplate>
                  <input id="chkSelectAll" name="SelectAll" type="checkbox" onclick="chkSelectAll_CheckedChanged" AutoPostBack="true"  />
             </HeaderTemplate>
       </igtbl:TemplatedColumn>
     </Columns>
   </igtbl:UltraGridBand>
  </Bands>
 </igtbl:ultrawebgrid>

The ultrawebgrid shows a column containing checkboxes, and the header of the same column contains a checkbox. 
I want a c# function chkSelectAll_CheckedChanged, which is called when the checkbox in header column is clicked.
It should select all the checkboxes in all the rows, if they are not already selected(i.e. if only some or none of them are selected). And if all of them are selected, it should deselect them.

I am using .net 4.0 framework.

Please help with the c# code which that function should contain.

Parents
No Data
Reply
  • 49378
    Verified Answer
    posted

    Hi sh2311g,

    Thank you for posting in the community.

    In this scenario I suggest that you use an ASP Checkbox control in your column header's template:

                            

     <asp:CheckBox ID="headerCheckbox" runat="server" AutoPostBack="True"
                                oncheckedchanged="headerCheckbox_CheckedChanged" />

    Here is also some sample code for the server-side handler:

        public void headerCheckbox_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox header = sender as CheckBox;

            if (header.Checked)
            {
                foreach (UltraGridRow row in UltraWebGrid1.Rows)
                {
                    row.Cells.FromKey("CheckboxCol").Value = true;

                }
            }
            else
            {
                foreach (UltraGridRow row in UltraWebGrid1.Rows)
                {
                    row.Cells.FromKey("CheckboxCol").Value = false;

                }

            }
        }

     

    With this setup you would need to uncheck the header checkbox any time a row checbox is deselected. You may also find the following guide for checking all checkboxes in a column client-side useful:

    http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=5057

    Please note that the UltraWebGrid control is now outdated and as of .NetAdvantage 2011 Volume 2 is no longer included in our product package. I would suggest that you consider switching to the WebDataGrid/WebHieararchicalDataGrid. More information regarding these controls is available at:

    http://help.infragistics.com/NetAdvantage/ASPNET/2011.2/CLR4.0/?page=Web_WebDataGrid_WebDataGrid.html

    Additional samples demonstrating the features of these grids can be found at:
    http://samples.infragistics.com/aspnet/

    Feel free to contact me if you have any questions.

Children