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

Auto checkbox in Telerik Reporting

4 Answers 131 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ebenezer
Top achievements
Rank 1
Ebenezer asked on 05 Aug 2013, 01:01 AM
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> 



4 Answers, 1 is accepted

Sort by
0
Accepted
Angel Petrov
Telerik team
answered on 07 Aug 2013, 02:59 PM
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.
0
Ebenezer
Top achievements
Rank 1
answered on 07 Aug 2013, 03:38 PM
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. 
0
Accepted
Angel Petrov
Telerik team
answered on 12 Aug 2013, 11:30 AM
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.
0
Ebenezer
Top achievements
Rank 1
answered on 12 Aug 2013, 02:10 PM
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



Tags
General Discussions
Asked by
Ebenezer
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Ebenezer
Top achievements
Rank 1
Share this question
or