Auto checkbox in Telerik Reporting

5 posts, 2 answers
  1. Ebenezer
    Ebenezer avatar
    39 posts
    Member since:
    Dec 2012

    Posted 04 Aug 2013 Link to this post

    I am developing Telerik Reporting and Inside a RadGrid I have checkboxes next to the dispalyed columns. What I want is, when the report load for the first time, the first 5 checkboxes should be checked automatically. User can uncheck or select up to 8 items and on preview button click see only the items checked.
    All the radgrid columns am being  populated  with AutoGenerateColumns="True" from stored procedure. 
    I have added this code and can see the checkboxes. How do I default the first 5 items as checked

    <MasterTableView AllowMultiColumnSorting="true" NoMasterRecordsText="There are no data records to display."> 
                                                <Columns>
                                                  <telerik:GridTemplateColumn HeaderText=""> 
                                                    <ItemTemplate> 
                                                        <asp:CheckBox ID="CheckBoxStatus" runat="server" AutoPostBack="true"  /> 
                                                    </ItemTemplate> 



  2. Answer
    Angel Petrov
    Admin
    Angel Petrov avatar
    1095 posts

    Posted 07 Aug 2013 Link to this post

    Hello Ebenezer,

    In order to check the first five check boxes you can subscribe to the OnItemDataBound event, obtain a reference to the check box controls in the ItemTemplate and change their state. For achieving this you can use the code snippets provided below:

    ASPX:
    <telerik:GridTemplateColumn UniqueName="CheckBoxColumn">
                      <ItemTemplate>
                          <asp:CheckBox ID="CheckBoxStatus" runat="server" AutoPostBack="true"  />
                      </ItemTemplate>
                  </telerik:GridTemplateColumn>

    C#
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
       {
           GridDataItem item = e.Item as GridDataItem;
           if (item != null && item.ItemIndex < 5)
           {
               (item["CheckBoxColumn"].FindControl("CheckBoxStatus") as CheckBox).Checked = true;   
           }
       }


    Regards,
    Angel Petrov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  3. Ebenezer
    Ebenezer avatar
    39 posts
    Member since:
    Dec 2012

    Posted 07 Aug 2013 Link to this post

    Hi  Petrov.,
    Thanks for your response. Your solution works great but one issue that I have is, I have a print button and using a session  want users  to see only the items Checked.  That is not working. 
  4. Answer
    Angel Petrov
    Admin
    Angel Petrov avatar
    1095 posts

    Posted 12 Aug 2013 Link to this post

    Hello Ebenezer,

    I would like to ask you to clarify. What action will the mentioned print button perform? Will it export the content of the grid or only obtain a reference to the grid items which check boxes are checked? If the last is the requirement you can obtain a reference to the checked items in the click event handler like demonstrated below:
    protected void PrintButton_Click(object sender, EventArgs e)
       {
           for (int i = 0; i < RadGrid1.Items.Count; i++)
           {
               GridDataItem item = RadGrid1.Items[i];
               CheckBox checkBox = item.FindControl("CheckBoxStatus") as CheckBox;
               if (checkBox.Checked)
               {
                   //Place the logic here.
               }
           }
       }

    Regards,
    Angel Petrov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  5. Ebenezer
    Ebenezer avatar
    39 posts
    Member since:
    Dec 2012

    Posted 12 Aug 2013 Link to this post

    Hi Petrov 
    Got it working correctly. Thank you very much



     The print button will export the content of the grid. Also this code that you gave me is not acting correctly.

    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
       {
           GridDataItem item = e.Item as GridDataItem;
           if (item != null && item.ItemIndex < 5)
           {
               (item["CheckBoxColumn"].FindControl("CheckBoxStatus"as CheckBox).Checked = true;   
           }
       }

    After page load, user's should be able to change the checked items and can checked up to 8 items. This code is not allowing user's to change the checked items



Back to Top