Don't Allow Group Collapse

4 posts, 1 answers
  1. Ryan
    Ryan avatar
    61 posts
    Member since:
    Jul 2009

    Posted 19 Oct 2009 Link to this post

    I have a RadGrid that groups data based on a column's value, and would like the user to not be allowed to expand/collapse that group (I'm essentially grouping only so I can have a group title).  My RadGrid is defined as follows:

    <!-- RadGrid for Articles --> 
    <telerik:RadGrid runat="server" ID="rgArticles" AutoGenerateColumns="false" AllowSorting="false" GroupingEnabled="true">  
        <MasterTableView ShowHeader="false">  
          
            <%-- Columns --%> 
            <Columns> 
                <%-- Title --%> 
                <telerik:GridTemplateColumn> 
                    <ItemTemplate><a href="<%#Eval("EditionLocation")%>" title="<%#Eval("Summary")%>" target="_blank"><%#Eval("Title")%> (p<%#Eval("EditionPages")%>)</a></ItemTemplate>  
                </telerik:GridTemplateColumn> 
            </Columns> 
              
            <%-- GroupByExpressions --%> 
            <GroupByExpressions> 
                <telerik:GridGroupByExpression> 
                    <SelectFields> 
                        <telerik:GridGroupByField FieldName="Edition" HeaderValueSeparator="Edition: " HeaderText="<%=String.Empty %>" /> 
                    </SelectFields> 
                    <GroupByFields> 
                        <telerik:GridGroupByField FieldName="Edition" /> 
                    </GroupByFields> 
                </telerik:GridGroupByExpression> 
            </GroupByExpressions> 
              
        </MasterTableView> 
    </telerik:RadGrid> 

    How can I make this work?  Thank you!
  2. Answer
    Schlurk
    Schlurk avatar
    812 posts
    Member since:
    May 2009

    Posted 19 Oct 2009 Link to this post

    You could try this:
     
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)  
    {  
       if (e.Item is GridGroupHeaderItem)  
       {  
           GridGroupHeaderItem item = (GridGroupHeaderItem)e.Item;  
           DataRowView groupDataRow = (DataRowView)e.Item.DataItem;  
           (item.Cells[0].Controls[0] as Button).Enabled = false;  
       }  
    }  

    This will disable your button, and if you want to remove the button completely (aka remove the image etc.) you would do:
     
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)  
    {  
       if (e.Item is GridGroupHeaderItem)  
       {  
           GridGroupHeaderItem item = (GridGroupHeaderItem)e.Item;  
           DataRowView groupDataRow = (DataRowView)e.Item.DataItem;  
           item.Cells[0].Controls.Clear();   
       }  
    }  

    Hope this helps!


  3. Ryan
    Ryan avatar
    61 posts
    Member since:
    Jul 2009

    Posted 19 Oct 2009 Link to this post

    That did the trick!  Thanks for the prompt reply!
  4. Mati
    Mati avatar
    1 posts
    Member since:
    Aug 2009

    Posted 13 Jan 2017 in reply to Schlurk Link to this post

    Hi,

     

    Could you tell me how I can add a custom css class to the expand buttons on each group? Or how to get in client side all the expand buttons have been disabled from server side?

     

    Thanks in advance!

Back to Top