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

Add Checkbox Control To Special Header Group

7 Answers 319 Views
Grid
This is a migrated thread and some comments may be shown as answers.
shahab
Top achievements
Rank 1
shahab asked on 18 Mar 2012, 10:22 AM

Hi dude,
I have a RadGrid in Asp.net with three groups. I want to Have a checkbox on the last group header. I do not need to have checkbox in other group header. WHat should I do?

Tnx alot

7 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 19 Mar 2012, 08:13 AM
Hi shahab,

Looking at your post, I figure out that you need to add the CheckBox to the last group header. Although your attachment depicts as if you want to remove the checkboxes in red. Anyways use following code to add CheckBox on the last group header.

C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
   foreach(GridGroupHeaderItem headeritem in RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader))
   {
     CheckBox chk = new CheckBox();
     if (headeritem.GroupIndex.Split('_').Length == 3)//third Group Header
     {           
       (headeritem as GridGroupHeaderItem).DataCell.Controls.Add(chk);
     }
  }
}

Hope this helps.

Thanks,
-Shinu.

0
shahab
Top achievements
Rank 1
answered on 20 Mar 2012, 09:16 PM
Hi,
Tnx Shinu. It is ok! But There is a problem, When I add checkbox to the third header rendered header Group title was removed. There is no group header. Group Header text is in "headeritem.DataCell.Text" property. When add control to headeritem, title is removed.
0
Shinu
Top achievements
Rank 2
answered on 21 Mar 2012, 06:02 AM
Hi Shahab,

The following code snippet shows one option to have both the control and groupheader text together.

C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
 
        foreach (GridGroupHeaderItem headeritem in RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader))
        {
            CheckBox chk = new CheckBox();
            if (headeritem.GroupIndex.Split('_').Length == 3)//third Group Header
            {
                string text = headeritem.DataCell.Text;
                (headeritem as GridGroupHeaderItem).DataCell.Controls.Add(chk);
                chk.Text = text;
            }
        }
    }

Thanks,
-Shinu.

0
shahab
Top achievements
Rank 1
answered on 21 Mar 2012, 08:06 AM
Hi,
1.I think this solution is very bad. Telerik should prepare access to group items with index or name of group.
2.Now I want to access to DataKeyNames from groupheaderitem. For example "codetest" and "uniqcode".

 foreach (GridGroupHeaderItem headeritem in ResultTestRadGrid.MasterTableView.GetItems(GridItemType.GroupHeader))
            {
                if (headeritem.GroupIndex.Split('_').Length == 3
                    && ((CheckBox)(headeritem as GridGroupHeaderItem).DataCell.Controls[0]).Checked)
                {
                    //ResultTestSqlDataSource.UpdateParameters["codetest"].DefaultValue = headeritem.GetDataKeyValue("codetest").ToString();
                    //ResultTestSqlDataSource.UpdateParameters["uniqcode"].DefaultValue = item.GetDataKeyValue("Uniqcode").ToString();
                    //ResultTestSqlDataSource.Update();
                }
            }
            ResultTestRadGrid.Rebind();
3.How Can I check checbox.Checked? this line of code is not ok:
((CheckBox)(headeritem as GridGroupHeaderItem).DataCell.Controls[0]).Checked)

Tnx alot.....
0
Tsvetina
Telerik team
answered on 26 Mar 2012, 07:58 AM
Hello Shahab,

I would recommend you to use the GridGroupHeaderTemplate to declare the checkbox and the text that you want to be shown. See this demo:
Grid Group Header and Footer Templates

Then, you could access all headers in the RadGrid PreRender event and hide the checkboxes which you do not want to be visible. If you use the GetItems method, the headers should be returned in their order of appearance in RadGrid:
RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader) //this returns an array of headers


Kind regards,
Tsvetina
the Telerik team
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 their blog feed now.
0
shahab
Top achievements
Rank 1
answered on 26 Mar 2012, 04:42 PM
Hi
1.I can not solve my problem. mentioned method is not ok becuase I have 3 group and I want to add Checkbox To the 3th groupHeader. With Grid Group Header and Footer Templates , CheckBoxes add to all groupHeader
      <GroupHeaderTemplate>
            <asp:Label runat="server" ID="Label5" Text='<%# (((GridGroupHeaderItem)Container).AggregatesValues["name"]) + "" + (((GridGroupHeaderItem)Container).AggregatesValues["Sname"])  +""+ (((GridGroupHeaderItem)Container).AggregatesValues["nametest"])%>'>
                </asp:Label>
                <asp:CheckBox ID="IsOkCheckBox" runat="server" Text="Hi" />
            </GroupHeaderTemplate>
I think to solve this problem I should hide other checkboxes:
 foreach (GridGroupHeaderItem headeritem in ResultTestRadGrid.MasterTableView.GetItems(GridItemType.GroupHeader))
        {            
            if (headeritem.GroupIndex.Split('_').Length != 3)
            {
                ((CheckBox)headeritem.FindControl("IsOkCheckBox")).Visible = false;
            }            
        }
however I think it is a very bad solution!:((

2.I just add one Label with different  "(((GridGroupHeaderItem)Container).AggregatesValues["???"])". Items are connected with "+" but items are displayed in different groupHeader!!!!
Please see the files.
0
Tsvetina
Telerik team
answered on 29 Mar 2012, 12:33 PM
Hello Shahab,

As mentioned in my prevous post, by specifying the template, you get the checkbox to show in each header but you could access and hide the unneeded checkboxes in the ItemCreated or PreRender event of the grid.

From your second screenshot I could not understand what exactly happens in your grid headers. Are they not bound to the aggregate values as shown in the demo? What is the expected output?

All the best,
Tsvetina
the Telerik team
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 their blog feed now.
Tags
Grid
Asked by
shahab
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
shahab
Top achievements
Rank 1
Tsvetina
Telerik team
Share this question
or