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

Collapse / Expand in Grouping

5 Answers 104 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Maxim Tairov
Top achievements
Rank 1
Maxim Tairov asked on 19 Nov 2008, 04:01 PM

Hello telerik, First of all thanks a lot for good components!

But I have a small problem: 

I use  my custom column (inherit from BoundColumn) in RadGrid which show small thumbnail image (When user click to Image new browser window is opened and show full - size image). During OnItemDataBound event I rewrite default Controls container of custome Column, by adding HyperLink control for showing thumbnail image.

Besides my Grid has an grouping ability. But  when I try to expand/collapse my groupped data I can't see thumbnail images in cell because OnItemDataBound doesn't raised. In this case I call RadGrid.Rebind() in OnItemCommand handler, but function doesn't work properly - Groupping item doesn't expand/collapse. Or one item is collapse but another expand. How can I support Custom Column data binding and expand/collapse support?

Please Help.

5 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 19 Nov 2008, 04:03 PM
Hi Maxim,

Please add desired controls using ItemCreated instead ItemDataBound.

Regards,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Maxim Tairov
Top achievements
Rank 1
answered on 20 Nov 2008, 10:35 AM
This is a good idea but OnItemCreated raise before OnItemBataBound and my changes which was made in OnItemCreated is deleted. As a result I see 'System.Byte[]' as a cell value. How can I save my changes after binding?
0
Sebastian
Telerik team
answered on 20 Nov 2008, 11:08 AM
Hello Maxim,

You can add the controls to the grid column cells intercepting the ItemCreated event and bind those controls to data hooking the ItemDataBound event of the control. Review the following topic from the documentation which explains the major differences between both events:

http://www.telerik.com/help/aspnet-ajax/grddistinguishdifferencesbetweenitemcreateditemdatabound.html

Best regards,
Stephen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Maxim Tairov
Top achievements
Rank 1
answered on 20 Nov 2008, 04:29 PM

Not sure, that topic can help to me. All point in it is clear. I have modified my code: transfer creation of HyperLink in cell from

OnItemDataBound to OnItemCreated. I am just add a HyperLink to a GridDataItem["ImageColumn"].Controls  without ANY binding operation:

protected override void OnItemCreated(GridItemEventArgs e)  
{  
  base.OnItemCreated(e);  
  if (e.Item is GridDataItem && Page.IsPostBack)  
  {  
    GridDataItem dataItem = e.Item as GridDataItem;    
 
    HyperLink link = new HyperLink();  
    dataItem["ImageColumn"].Controls.Add(link);  
    dataItem["ImageColumn"].HorizontalAlign = HorizontalAlign.Center;  
      
    link.ImageUrl = "LinkUrl";         //Url to thubmnail image  
    link.NavigateUrl = "NavigateUrl";  //Url to open full-size image    
 
    link.Target = "imageWindow";   
  }  
}

It's looks good - but when page is Loaded I don't see any Links - just a System.Byte[]. I don't need bind any data to my created HyperLink, how can I skip binding for specific cell?

0
Sebastian
Telerik team
answered on 24 Nov 2008, 03:13 PM
Hello Maxim,

Consider clearing the controls from the Controls collection of the set prior to adding the HyperLink to it, namely:

protected override void OnItemCreated(GridItemEventArgs e)     
{     
  base.OnItemCreated(e);     
  if (e.Item is GridDataItem && Page.IsPostBack)     
  {     
    GridDataItem dataItem = e.Item as GridDataItem;       
      
    dataItem["ImageColumn"].Controls.Clear();    
    HyperLink link = new HyperLink();  
    dataItem["ImageColumn"].HorizontalAlign = HorizontalAlign.Center;     
         
    link.ImageUrl = "LinkUrl";         //Url to thubmnail image     
    link.NavigateUrl = "NavigateUrl";  //Url to open full-size image       
    
    link.Target = "imageWindow";   
 
    dataItem["ImageColumn"].Controls.Add(link);      
  }     
}   
 

Thus you should be able to skip the default binding mechanism for controls residing in the respective grid cell.

Kind regards,
Stephen,
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Maxim Tairov
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Maxim Tairov
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or