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

RadGrid nested in RadTreeList using NeedDataSource not loading correctly.

1 Answer 58 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 12 Sep 2013, 01:32 AM
Hi,

I've got a problem where i'm trying to build a webpart that uses a RadTreeList that nests a RadGrid within the second column of the RadTreeList to give me a hierarchy of grids. This allows me to view a set of grid data at each level of a hierarchy and alter the data within, due to the size of the hierarchies and grids i only want to load the grid data if an item has been selected within a filter control.

I have managed to create my RadTreeList with the nested Grids which loads and add a NeedDataSource to each grid as its being loaded. This will load the initial set of data and i can then trigger the edit on the grids which seems to work OK.

My problem is when i come to deselect a grid from my filter control and then in the Grid NeedDataSource it sets the datasource back to null and in turn i would expect on the loading of the grid the grid shouldn't be displayed as its datasource is empty. However for some reason the grid is still persisting the previously loaded data? Can anyone tell me why this is, have i missed something?

I have posted my HTML/ASP markup and C# code below:

<telerik:RadTreeList ID="rtl_TaxonomyGrids" runat="server" AutoGenerateColumns="False" DataKeyNames="Allocation" ParentDataKeyNames="Parent_Allocation" OnItemDataBound="rtl_TaxonomyGrids_ItemDataBound" OnLoad="rtl_TaxonomyGrids_Load" OnNeedDataSource="rtl_TaxonomyGrids_NeedDataSource" OnItemCreated="rtl_TaxonomyGrids_ItemCreated">
    <Columns>
        <telerik:TreeListBoundColumn UniqueName="Name" DataField="Name" HeaderText="Name">
            <HeaderStyle Width="100px"></HeaderStyle>
        </telerik:TreeListBoundColumn>
        <telerik:TreeListTemplateColumn UniqueName="PermissionsGrid" HeaderText="Permissions"
            DataField="Allocation">
            <ItemStyle CssClass="TreeGridCell NoPadding"></ItemStyle>
            <ItemTemplate>
                <asp:Label ID="lb_GridAllocation" Font-Bold="true" Font-Italic="true" Text='<%# Eval("Allocation") %>'
                    Visible="false" runat="server"></asp:Label>
                <telerik:RadGrid ID="rg_TaxonomyGroupProfiling" AllowMultiRowSelection="True" BorderStyle="None" runat="server" AutoGenerateColumns="false" OnItemDataBound="rg_TaxonomyGroupProfiling_ItemDataBound" OnItemCreated="rg_TaxonomyGroupProfiling_ItemCreated">
                    <ClientSettings AllowExpandCollapse="true">
                        <Selecting AllowRowSelect="True" UseClientSelectColumnOnly="True"></Selecting>                     
                    </ClientSettings>
                    <MasterTableView ClientDataKeyNames="Allocation" Width="100%" EditMode="InPlace">
                        <Columns>                        
                            <telerik:GridClientSelectColumn UniqueName="ClientSelectColumn">
                            </telerik:GridClientSelectColumn>
                            <telerik:GridBoundColumn Visible="false" UniqueName="Allocation" DataField="Allocation" HeaderText="Allocation" ReadOnly="True">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn UniqueName="UserGroup" DataField="UserGroup" HeaderText="UserGroup" ReadOnly="True">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn UniqueName="Status" DataField="Status" HeaderText="Status" ReadOnly="True">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn  UniqueName="Inherits" DataField="Inherits" HeaderText="Inherits" ColumnEditorID="GridTextBoxColumnEditor1">
                            </telerik:GridBoundColumn>                          
                            <telerik:GridBoundColumn UniqueName="View" DataField="View" HeaderText="View" ColumnEditorID="GridTextBoxColumnEditor1">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn  UniqueName="Competent" DataField="Process" HeaderText="Competent" ColumnEditorID="GridTextBoxColumnEditor1">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn UniqueName="BatchSize" DataField="BatchSize" HeaderText="Batch Size" ColumnEditorID="GridTextBoxColumnEditor1">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn UniqueName="Escalate" DataField="Escalate" HeaderText="Escalate" ColumnEditorID="GridTextBoxColumnEditor1">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn  UniqueName="Suspend" DataField="Suspend" HeaderText="Suspend" ColumnEditorID="GridTextBoxColumnEditor1">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn UniqueName="SamplingX" DataField="SamplingX" HeaderText="SamplingX" ColumnEditorID="GridTextBoxColumnEditor1">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn UniqueName="SamplingY" DataField="SamplingY" HeaderText="SamplingY" ColumnEditorID="GridTextBoxColumnEditor1">
                            </telerik:GridBoundColumn>
                            <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn1">
                                <HeaderStyle Width="20px"></HeaderStyle>
                                <ItemStyle CssClass="MyImageButton"></ItemStyle>
                            </telerik:GridEditCommandColumn>
                        </Columns>
                    </MasterTableView>
                </telerik:RadGrid>
                <telerik:GridTextBoxColumnEditor ID="GridTextBoxColumnEditor1" runat="server" TextBoxStyle-Width="35px">
                </telerik:GridTextBoxColumnEditor>
                <telerik:GridDropDownListColumnEditor ID="GridDropDownListColumnEditor1" runat="server"
                    DropDownStyle-Width="70px">
                </telerik:GridDropDownListColumnEditor>               
            </ItemTemplate>
        </telerik:TreeListTemplateColumn>
    </Columns>
</telerik:RadTreeList>

protected void rtl_TaxonomyGrids_NeedDataSource(object sender, Telerik.Web.UI.TreeListNeedDataSourceEventArgs e)
{
    if (sender is RadTreeList)
    {
        RadTreeList tree = sender as RadTreeList;
        tree.DataSource = null;
        tree.DataSource = dh.GetTaxonomyData();
    }
}
 
protected void rtl_TaxonomyGrids_ItemCreated(object sender, TreeListItemCreatedEventArgs e)
{
    if (e.Item is TreeListDataItem)
    {               
        RadGrid grid = (RadGrid) e.Item.FindControl("rg_TaxonomyGroupProfiling");
        grid.NeedDataSource += new GridNeedDataSourceEventHandler(rg_TaxonomyGroupProfiling_NeedDataSource);
    }
}
 
protected void rg_TaxonomyGroupProfiling_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    if (sender is RadGrid)
    {
        RadGrid grid = sender as RadGrid;
        grid.MasterTableView.DataSource = null;
        grid.DataSource = null;
 
        string taxSelection = this.GroupProfilerContainer.GroupProfilerContext.CriteriaSettings.Selection["Taxonomy"].ToString();
        string gpSelection =  ConverToWhereClause(this.GroupProfilerContainer.GroupProfilerContext.CriteriaSettings.Selection);
 
        TreeListDataItem nestedItem = (TreeListDataItem)(grid.NamingContainer);
        string allocation = nestedItem.GetDataKeyValue("Allocation").ToString();
 
        if (!string.IsNullOrEmpty(taxSelection))
        {
            if (taxSelection.Split(',').Contains(allocation))
            {
                grid.DataSource = dh.GetPermissionsData(allocation, gpSelection);
            }
        }
    }
}

Thanks,
JC

1 Answer, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 16 Sep 2013, 03:47 PM
Hello John,

You code snippets do not give the whole picture. If you deselect a row, you need to the grid to be shown empty, right? Or you need it not to be displayed whatsoever? Could you share the code for the selection/deselection? On the face of it, it seems that you need to rebind the grid when you deselect a row from the treelist but without more information it is difficult to say what exactly  is going on with the controls.

I'd suggest that you better open up a formal support ticket and send your code as a file attachment.
 
Regards,
Tsvetoslav
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Share this question
or