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

client side expand on link click within gridtemplatecolumn

1 Answer 24 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Developer Developer
Top achievements
Rank 1
Developer Developer asked on 07 Nov 2008, 07:35 PM

I have an asp:LinkButton within a telerik:GridTemplateColumn.  I want to be able to click on the link and expand that row client side.  Is anybody aware of a code example that shows how this could be done?  Any help would be greatly appreciated.

 

 




 

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 10 Nov 2008, 04:49 AM
Hello,

You can check out the following code to expand or collapse the hierarchial grid on clicking a linkbutton.
aspx:
<telerik:GridTemplateColumn UniqueName="TemplateColumn"
  <ItemTemplate> 
     <asp:LinkButton ID="LinkButton1" runat="server" Text=Expand/Collapse></asp:LinkButton> 
  </ItemTemplate> 
</telerik:GridTemplateColumn> 

cs:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    {       
       if (e.Item is GridDataItem) 
        { 
            GridDataItem dataItem = (GridDataItem)e.Item; 
            LinkButton lnk = (LinkButton)dataItem.FindControl("LinkButton1"); 
            int index = e.Item.ItemIndex; 
            lnk.Attributes.Add("onclick", "return expandcollapse('" + index + "');"); 
        } 
    } 

js:
function expandcollapse(key) 
 { 
   var grid=$find("<%=RadGrid1.ClientID %>"); 
   var table=grid.get_masterTableView(); 
   var row=table.get_dataItems()[key]; 
    if(row.get_expanded() == false)   
        {   
            row.set_expanded(true);                  
             
        }   
        else  
        {   
            row.set_expanded(false);   
        } 
 } 

Thanks
Princy.
Tags
Grid
Asked by
Developer Developer
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or