Question

I have a grid similar to the below one, mine has a few more data columns.
I would like to hide ID and ParentID columns. But if I hide ID, Expand/Collapse functionality ceases to exist. All rows are displayed as in a normal table.

enter image description here

How do I achieve it?

<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" OnColumnCreated="RadGrid1_ColumnCreated"
        OnItemCreated="RadGrid1_ItemCreated" OnItemDataBound="RadGrid1_ItemDataBound" AutoGenerateColumns="false" OnPreRender="RadGrid1_PreRender">
        <MasterTableView HierarchyDefaultExpanded="true" HierarchyLoadMode="Client" AllowSorting="false"
            DataKeyNames="OrderId, MasterId" Width="100%">
            <SelfHierarchySettings ParentKeyName="MasterId" KeyName="OrderId" MaximumDepth="1" />
            <Columns>
                <telerik:GridTemplateColumn HeaderText="Order ID" UniqueName="OrderId" Display="false">                    
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn HeaderText="Name">
                    <ItemTemplate><%# Eval("Name") %></ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn HeaderText="Number">
                    <ItemTemplate><%# Eval("PassengerNumber") %></ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn HeaderText="Total">
                    <ItemTemplate><%# Eval("Total") %></ItemTemplate>
                </telerik:GridTemplateColumn>
            </Columns>
        </MasterTableView>
        <ClientSettings AllowExpandCollapse="true" />
    </telerik:RadGrid>

Display="false" still keeps OrderID in the html, so this functionality should work, but it doesn't.

Any idea anyone?

Was it helpful?

Solution

Ok. I've found a solution after taking a closer look at code behind.
In my case, I wanted Expand-Collapse button on Name column.
For that:
In .aspx file, I had to add Name to DataKeyNames. Removed ID & ParentId grid columns. Added UniqueName attribute to Name gridcolumn with value Name.
In code behind, I have passed Name for uniquecolumnname when creating Expand-Collapse button.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top