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

Grid Grouping Column

4 Answers 128 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ban
Top achievements
Rank 1
Ban asked on 13 Feb 2009, 01:48 PM
Hi,
please can you help me with this, I am using RadGrid and I am grouping my column by code behind, the user select which column he want to group by and then press a command button I put in my page and by this button I used GroupByExpressions property to group my Grid, the question is: after the grid grouped a new column is added which is the grouping column and with each group header there is (+),(-) sign for collapse and expand the grouped rows, I put another button in my page to give the user the option to collapse or expand all the grouped rows and every time he press the button I used "GroupsDefaultExpanded" property to switch between True and False. is there any way to put the sign (+,- the collapse sign) in the header of the new added group column ??  and when the user press on it  collapse or expand all the rows instead of using button for this, it will be more elegant and useful. by the way I tried to reach this new added grouping column but I could not.
Please advise me if I can do this or not.
Thanks

Ban

 

 

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 16 Feb 2009, 12:07 PM
Hi Ban,

I guess you are trying to add the button in the Header of the newly added GroupSplitterColumn. If so give a try with the following code snippet and see whether it helps.

CS:
 protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    { 
        
        if (e.Item is GridHeaderItem) 
        { 
            GridHeaderItem header = (GridHeaderItem)e.Item; 
            ImageButton imgbtn = new ImageButton(); 
            imgbtn.ID = "btnExpndAll"
            imgbtn.ImageUrl = "~/Images/Image1.gif"
            imgbtn.Click += new ImageClickEventHandler(imgbtn_Click); 
            header["column"].Controls.Add(imgbtn); 
        } 
  
    } 
    void imgbtn_Click(object sender, ImageClickEventArgs e) 
    { 
        RadGrid1.MasterTableView.GroupsDefaultExpanded = !RadGrid1.MasterTableView.GroupsDefaultExpanded; 
        RadGrid1.MasterTableView.Rebind(); 
    } 


Thanks
Shinu



0
Ban
Top achievements
Rank 1
answered on 16 Feb 2009, 02:23 PM

Hi Shinu,

Thanks for replay, the code you send to me was very useful and I try it on my Grid Columns and it worked very nice, but the problem is how can I reach the Grouping column "GridGroupSplitterColumn" ?? I try to catch it in "ColumnCreated" event, I check with "e.Column.ColumnType" inside the event but how can I put the Header button in it especially the GridHeaderItem need the UniqueName and I could not find the Group column one.
Please jelp and advice me, thanks again

Ban

 

 

 

 

0
Shinu
Top achievements
Rank 2
answered on 17 Feb 2009, 05:19 AM
Hi Ban,

I tried with the above code and it is working well on my end."column" is the UniqueName of the GroupSplitterColumn. Can you try with exact code provided below and see whether it is working.

CS:
 protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    { 
 
        if (e.Item is GridHeaderItem) 
        { 
               GridHeaderItem header = (GridHeaderItem)e.Item; 
               if (RadGrid1.MasterTableView.GroupByExpressions.Count > 0) 
               { 
                   ImageButton imgbtn = new ImageButton(); 
                   imgbtn.ID = "btnExpndAll"
                   imgbtn.ImageUrl = "~/Images/Image1.gif"
                   imgbtn.Click += new ImageClickEventHandler(imgbtn_Click); 
                   header["column"].Controls.Add(imgbtn); 
               } 
             
        }  
   
    } 
    void imgbtn_Click(object sender, ImageClickEventArgs e) 
    { 
        RadGrid1.MasterTableView.GroupsDefaultExpanded = !RadGrid1.MasterTableView.GroupsDefaultExpanded; 
        RadGrid1.MasterTableView.Rebind(); 
    }  


Regards
Shinu.
0
Ban
Top achievements
Rank 1
answered on 18 Feb 2009, 11:21 AM
Hi Shinu,
Thanks for your replay and your patience with me, the misunderstand was I did not  know that the name "column" is the UniqueName of the GroupSplitterColumn. I thought when I read your solution that I should put the UniqueName of the GroupSplitterColumn, I use the code and it is wonderful just like what I want, Thanks alot for your cooperation.

Ban
Tags
Grid
Asked by
Ban
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Ban
Top achievements
Rank 1
Share this question
or