Retain expanded/selected state in hierarchy on rebind

Thread is closed for posting
20 posts, 1 answers
  1. Answer
    63F75A2C-1F16-4AED-AFE8-B1BBD57646AD
    63F75A2C-1F16-4AED-AFE8-B1BBD57646AD avatar
    1572 posts
    Member since:
    Oct 2004

    Posted 08 Feb 2007 Link to this post

    Requirements

    RadGrid for ASP .NET version

    RadControls for ASP .NET AJAX version

    4.x and later


    2008.1.415 and later

    .NET version

    2.0 and later

    Visual Studio version

    2005 and later

    Programming language

    C#

    Browser support

    all supported by RadGrid for ASP .NET


    all browsers supported by RadControls for ASP .NET AJAX


    PROJECT DESCRIPTION

    By default when you rebind a parent table in hierarchical grid the settings/expanded state for the nested tables will be lost. This is because the refresh action resets all previous settings applied for the nested controls to avoid viewstate inconsistencies/unexpected behavior.

    This project represents how to retain the expanded/selected state for grid items in hierarchy upon a rebind command (hitting the [Refresh] button in an arbitrary command item or the [Rebind grid] button below the grid). Note that the data refresh will be performed through an ajax request when you hit a [Refresh] button and with standard postback from the button outside of the grid body. Nonetheless, the expanded/selected items will retain their state in each level of the hierarchy.

    The items configuration is maintained in a custom manner in two variables stored in the Session state. Essentially, you need to update these variables on ItemCommand when the command name is:
    • RadGrid.ExpandCollapseCommandName
    • RadGrid.SelectCommandName
    • RadGrid.DeselectCommandName

    The restoration of the previous hierarchy configuration is performed inside the DataBound handler of the grid when the data is already bound - this is the safe place to apply the expand/select settings which are otherwise lost on subsequent rebind.

    Feel free to extend the example in a custom way if other parts of the master/child tables state should be maintained as well.

  2. 05EB1600-F175-45B1-8CA6-30746ACCB0A9
    05EB1600-F175-45B1-8CA6-30746ACCB0A9 avatar
    20 posts
    Member since:
    Apr 2007

    Posted 25 Apr 2007 Link to this post

    i have a problem when i expand the child grid and select the child row for editing and click the edit select products linkbutton from customitemtemplate ....it changes to update products and on clicking the cancel button in child grid....it doesnt change to edit select linkbutton
    please check my code
    i need it urgently...
    thanx in advance
    <
    radG:RadGrid ID="RadGrid1"

    AllowMultiRowSelection="true"

    AllowMultiRowEdit="true"

    Skin="WebBlue"

    runat="server"

    AllowAutomaticDeletes="True"

    AllowAutomaticInserts="True"

    Width="97%"

    PageSize="14"

    AllowAutomaticUpdates="True"

    AllowPaging="True"

    AutoGenerateColumns="False"

    DataSourceID="SqlDatasource1"

    ShowStatusBar="true" EnableAJAX="true"

    EnableAJAXLoadingTemplate="false"

    LoadingTemplateTransparency="50"

    GridLines="None" CssClass="RadGrid"

    >

    <PagerStyle Mode="Slider" />

    <ClientSettings>

    <Selecting AllowRowSelect="true" />

    </ClientSettings>

    <MasterTableView CommandItemDisplay="Top"

    DataKeyNames="ProductID,SupplierID"

    DataSourceID="SqlDatasource1"

    EditMode="EditForms"

    AutoGenerateColumns="False"

    Width="100%">

    <DetailTables>

    <radG:GridTableView CommandItemDisplay="Top"

    DataKeyNames="SupplierID"

    DataSourceID="SqlDatasource4"

    Width="100%"

    Gridlines= "Horizontal"

    style="border-color:#d5b96a"

    CssClass="RadGrid2"

    AllowMultiRowSelection="true"

    AllowMultiRowEdit="true"

    Skin="WebBlue"

    runat="server"

    AllowAutomaticDeletes="True"

    AllowAutomaticInserts="True"

    PageSize="14"

    AllowAutomaticUpdates="True"

    AllowPaging="True"

    AutoGenerateColumns="False"

    ShowStatusBar="true" EnableAJAX="true"

    EnableAJAXLoadingTemplate="false"

    LoadingTemplateTransparency="50"

    >

    <ParentTableRelation>

    <radG:GridRelationFields DetailKeyField="SupplierID"

    MasterKeyField= "SupplierID" />

    </ParentTableRelation>

    <%-- <DetailTables>

    <radG:GridTableView DataKeyNames="OrderID" DataMember="OrderDetails"

    Width= "100%" Gridlines="Horizontal" style="border-color:#d5b96a"

    CssClass= "RadGrid3">

    <ParentTableRelation>

    <radG:GridRelationFields DetailKeyField="OrderID"

    MasterKeyField= "OrderID" />

    </ParentTableRelation>

    <Columns>

    <radG:GridBoundColumn SortExpression="UnitPrice" HeaderText="Unit

    Price " HeaderButtonType="TextButton" DataField="UnitPrice" />

    <radG:GridBoundColumn SortExpression="Quantity"

    HeaderText= "Quantity" HeaderButtonType="TextButton"

    DataField= "Quantity" />

    <radG:GridBoundColumn SortExpression="Discount"

    HeaderText= "Discount" HeaderButtonType="TextButton"

    DataField= "Discount" />

    </Columns>

    </radG:GridTableView>

    </DetailTables>--%>

    <Columns>

    <radG:GridClientSelectColumn UniqueName="Select1">

    </radG:GridClientSelectColumn>

    <radG:GridBoundColumn SortExpression="SupplierID" HeaderText="SupplierID"

    HeaderButtonType= "TextButton" DataField="SupplierID" />

    <radG:GridBoundColumn SortExpression="CompanyName" HeaderText="companyName"

    HeaderButtonType= "TextButton" DataField="CompanyName" />

    <%--<radG:GridBoundColumn SortExpression="EmployeeID" HeaderText="EmployeeID"

    HeaderButtonType= "TextButton" DataField="EmployeeID" />--%>

    </Columns>

    </radG:GridTableView>

    </DetailTables>

    <CommandItemTemplate>

    Custom command item template &nbsp;

    <asp:LinkButton Style="vertical-align: bottom"

    ID="btnEditSelected"

    runat="server"

    CommandName="EditSelected"

    Visible='<%# RadGrid1.EditIndexes.Count == 0 %>'>

    <img style="border:0px" alt="" src="../../DataEditing/Img/Edit.gif" /> Edit Selected Products

    </asp:LinkButton>

    <asp:LinkButton ID="btnUpdateEdited"

    runat="server"

    CommandName="UpdateEdited"

    Visible='<%# RadGrid1.EditIndexes.Count > 0 %>'>

    <img style="border:0px" alt="" src="../../DataEditing/Img/Update.gif" /> Update Products

    </asp:LinkButton>&nbsp;

    <asp:LinkButton ID="btnCancel"

    runat="server"

    CommandName="CancelAll"

    Visible='<%# RadGrid1.EditIndexes.Count > 0 || RadGrid1.MasterTableView.IsItemInserted %>'>

    <img style="border:0px" alt="" src="../../DataEditing/Img/Cancel.gif" /> Cancel editing

    </asp:LinkButton>&nbsp;

    <asp:LinkButton ID="LinkButton2"

    runat="server"

    CommandName="InitInsert"

    Visible='<%# !RadGrid1.MasterTableView.IsItemInserted %>'>

    <img style="border:0px" alt="" src="../../DataEditing/Img/AddRecord.gif" /> Add new Product

    </asp:LinkButton>

    <asp:LinkButton ID="LinkButton3"

    runat="server"

    CommandName="PerformInsert"

    Visible='<%# RadGrid1.MasterTableView.IsItemInserted %>'>

    <img style="border:0px" alt="" src="../../DataEditing/Img/Insert.gif" /> Add this Product

    </asp:LinkButton>&nbsp;

    <asp:LinkButton ID="LinkButton1"

    OnClientClick="javascript:return confirm('Delete all selected Products?')"

    runat="server"

    CommandName="DeleteSelected">

    <img style="border:0px" alt="" src="../../DataEditing/Img/Delete.gif" /> Delete Selected Products

    </asp:LinkButton>&nbsp;&nbsp;&nbsp;

    <asp:LinkButton ID="LinkButton4"

    runat="server"

    CommandName="RebindGrid">

    <img style="border:0px" alt="" src="../../DataEditing/Img/Refresh.gif" /> Refresh Product list

    </asp:LinkButton><br />

    <asp:LinkButton ID="LinkButton11" Visible=true runat="server" CommandName="Deactivate"><img style="border:0px" alt="" src="../../DataEditing/Img/Delete.gif" />Deactivate Products</asp:LinkButton>

    &nbsp;

    </CommandItemTemplate>

    <Columns>

    <%-- <radG:GridEditCommandColumn ButtonType="ImageButton"

    UpdateImageUrl="..\..\DataEditing\Img\Update.gif"

    EditImageUrl="..\..\DataEditing\Img\Edit.gif"

    InsertImageUrl="..\..\DataEditing\Img\Insert.gif"

    CancelImageUrl="..\..\DataEditing\Img\Cancel.gif"

    UniqueName="EditCommandColumn">

    <HeaderStyle Width="20px" />

    </radG:GridEditCommandColumn>--%>

    <%-- <radG:GridClientDeleteColumn ConfirmText="Delete this product?"

    ButtonType="ImageButton"

    ImageUrl="..\..\DataEditing\Img\Delete.gif"

    CommandName="Delete" Text="Delete"

    UniqueName="DeleteColumn">

    <HeaderStyle Width="20px" />

    <ItemStyle HorizontalAlign="Center" />

    </radG:GridClientDeleteColumn>--%>

    <radG:GridClientSelectColumn UniqueName="Select">

    </radG:GridClientSelectColumn>

    <%-- <radG:GridClientSelectColumn HeaderStyle-Width="40px" />--%>

    <radG:GridBoundColumn DataField="ProductID"

    HeaderText="ID"

    ReadOnly="True"

    SortExpression="ProductID"

    UniqueName="ProductID"

    Visible="true">

    <HeaderStyle Width="20px" ForeColor="Silver" />

    <ItemStyle ForeColor="Silver" />

    </radG:GridBoundColumn>

    <radG:GridBoundColumn DataField="ProductName"

    HeaderText="ProductName"

    SortExpression="ProductName"

    UniqueName="ProductName">

    </radG:GridBoundColumn>

    <radG:GridDropDownColumn DataField="SupplierID"

    DataSourceID="SqlDatasource2"

    HeaderText="Supplier"

    ListTextField="CompanyName"

    ListValueField="SupplierID"

    UniqueName="SupplierID">

    </radG:GridDropDownColumn>

    <radG:GridDropDownColumn DataField="CategoryID"

    DataSourceID="SqlDatasource3"

    HeaderText="Category"

    ListTextField="CategoryName"

    ListValueField="CategoryID"

    UniqueName="CAtegorysID">

    </radG:GridDropDownColumn>

    <radG:GridBoundColumn DataField="UnitsInStock"

    HeaderText="Units In Stock"

    SortExpression="UnitsInStock"

    UniqueName="UnitsInStock">

    <HeaderStyle Width="50px" />

    </radG:GridBoundColumn>

    <radG:GridBoundColumn DataField="QuantityPerUnit"

    HeaderText="Quantity Per Unit"

    SortExpression="QuantityPerUnit"

    UniqueName="QuantityPerUnit"

    Visible="false">

    </radG:GridBoundColumn>

    <radG:GridCheckBoxColumn DataField="Discontinued"

    HeaderText="Discontinued"

    SortExpression="Discontinued"

    UniqueName="Discontinued"

    EditFormColumnIndex="1">

    <HeaderStyle Width="50px" />

    </radG:GridCheckBoxColumn>

    <radG:GridBoundColumn DataField="UnitsOnOrder"

    HeaderText="Units On Order"

    SortExpression="UnitsOnOrder"

    UniqueName="UnitsOnOrder"

    Visible="false"

    EditFormColumnIndex="1">

    </radG:GridBoundColumn>

    <radG:GridTemplateColumn HeaderText="UnitPrice"

    SortExpression="UnitPrice"

    UniqueName="TemplateColumn"

    EditFormColumnIndex="1">

    <HeaderStyle Width="80px" />

    <ItemTemplate>

    <asp:Label runat="server" ID="lblUnitPrice"

    Text='<%# Eval("UnitPrice", "{0:C}") %>'>

    </asp:Label>

    </ItemTemplate>

    <EditItemTemplate>

    <asp:TextBox runat="server" ID="tbUnitPrice"

    Text='<%# Bind("UnitPrice") %>'>

    </asp:TextBox>

    <span style="color: Red">*</span>

    <asp:RequiredFieldValidator ID="RequiredFieldValidator1"

    ControlToValidate="tbUnitPrice"

    ErrorMessage="This field is required"

    runat="server">

    </asp:RequiredFieldValidator>

    </EditItemTemplate>

    </radG:GridTemplateColumn>

    <radG:GridBoundColumn Visible="false"

    UniqueName="UnitPrice1"

    ReadOnly="true"

    ForceExtractValue="InBrowseMode"

    DataField="UnitPrice">

    </radG:GridBoundColumn>

    <radG:GridBoundColumn DataField="ReorderLevel"

    HeaderText="Reorder Level"

    SortExpression="ReorderLevel"

    UniqueName="ReorderLevel"

    Visible="false"

    EditFormColumnIndex="1">

    </radG:GridBoundColumn>

    </Columns>

    <EditFormSettings ColumnNumber="2"

    CaptionDataField="ProductName"

    CaptionFormatString="Edit properties of Product {0}">

    <FormTableItemStyle Wrap="False"></FormTableItemStyle>

    <FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle>

    <FormMainTableStyle GridLines="Horizontal"

    CellSpacing="0"

    CellPadding="3"

    BackColor="White" />

    <FormTableStyle CellSpacing="0"

    CellPadding="2"

    CssClass="module"

    Height="110px"

    BackColor="White" />

    <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>

    <FormStyle Width="1%"></FormStyle>

    <EditColumn ButtonType="ImageButton"

    UpdateImageUrl="..\..\DataEditing\Img\Update.gif"

    EditImageUrl="..\..\DataEditing\Img\Edit.gif"

    InsertImageUrl="..\..\DataEditing\Img\Insert.gif"

    CancelImageUrl="..\..\DataEditing\Img\Cancel.gif"

    InsertText="Insert Order"

    UpdateText="Update record"

    UniqueName="EditCommandColumn1"

    CancelText="Cancel edit">

    </EditColumn>

    <FormTableButtonRowStyle HorizontalAlign="Right"

    CssClass="EditFormButtonRow">

    </FormTableButtonRowStyle>

    </EditFormSettings>

    </MasterTableView>

    </radG:RadGrid><br />

    <asp:SqlDataSource ID="SqlDatasource1" runat="server"

    ConnectionString="Data Source=CONN-SRV2;Initial Catalog=Northwind;Persist Security Info=True;User ID=msol;Password=msol"

    ProviderName="System.Data.SqlClient"

    SelectCommand="SELECT * FROM [Products]" DeleteCommand="DELETE FROM [Products] WHERE [ProductID] = @original_ProductID AND [ProductName] = @original_ProductName AND [SupplierID] = @original_SupplierID AND [CategoryID] = @original_CategoryID AND [QuantityPerUnit] = @original_QuantityPerUnit AND [UnitPrice] = @original_UnitPrice AND [UnitsInStock] = @original_UnitsInStock AND [UnitsOnOrder] = @original_UnitsOnOrder AND [ReorderLevel] = @original_ReorderLevel AND [Discontinued] = @original_Discontinued"

    InsertCommand="INSERT INTO Products(ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued) VALUES (@ProductName,@SupplierID, @CategoryID, @QuantityPerUnit, @UnitPrice, @UnitsInStock, @UnitsOnOrder, @ReorderLevel, @Discontinued)"

    UpdateCommand="UPDATE [Products] SET [ProductName] = @ProductName, [SupplierID] = @SupplierID, [CategoryID] = @CategoryID, [QuantityPerUnit] = @QuantityPerUnit, [UnitPrice] = @UnitPrice, [UnitsInStock] = @UnitsInStock, [UnitsOnOrder] = @UnitsOnOrder, [ReorderLevel] = @ReorderLevel, [Discontinued] = @Discontinued WHERE [ProductID] = @original_ProductID AND [ProductName] = @original_ProductName AND [SupplierID] = @original_SupplierID AND [CategoryID] = @original_CategoryID AND [QuantityPerUnit] = @original_QuantityPerUnit AND [UnitPrice] = @original_UnitPrice AND [UnitsInStock] = @original_UnitsInStock AND [UnitsOnOrder] = @original_UnitsOnOrder AND [ReorderLevel] = @original_ReorderLevel AND [Discontinued] = @original_Discontinued"

    OldValuesParameterFormatString="original_{0}"

    ConflictDetection="CompareAllValues">

    <DeleteParameters>

    <asp:Parameter Name="original_ProductID" Type="Int32" />

    <asp:Parameter Name="original_ProductName" Type="String" />

    <asp:Parameter Name="original_SupplierID" Type="Int32" />

    <asp:Parameter Name="original_CategoryID" Type="Int32" />

    <asp:Parameter Name="original_QuantityPerUnit" Type="String" />

    <asp:Parameter Name="original_UnitPrice" Type="Decimal" />

    <asp:Parameter Name="original_UnitsInStock" Type="Int16" />

    <asp:Parameter Name="original_UnitsOnOrder" Type="Int16" />

    <asp:Parameter Name="original_ReorderLevel" Type="Int16" />

    <asp:Parameter Name="original_Discontinued" Type="Boolean" />

    </DeleteParameters>

    <UpdateParameters>

    <asp:Parameter Name="ProductName" Type="String" />

    <asp:Parameter Name="SupplierID" Type="Int32" />

    <asp:Parameter Name="CategoryID" Type="Int32" />

    <asp:Parameter Name="QuantityPerUnit" Type="String" />

    <asp:Parameter Name="UnitPrice" Type="Decimal" />

    <asp:Parameter Name="UnitsInStock" Type="Int16" />

    <asp:Parameter Name="UnitsOnOrder" Type="Int16" />

    <asp:Parameter Name="ReorderLevel" Type="Int16" />

    <asp:Parameter Name="Discontinued" Type="Boolean" />

    <asp:Parameter Name="original_ProductID" Type="Int32" />

    <asp:Parameter Name="original_ProductName" Type="String" />

    <asp:Parameter Name="original_SupplierID" Type="Int32" />

    <asp:Parameter Name="original_CategoryID" Type="Int32" />

    <asp:Parameter Name="original_QuantityPerUnit" Type="String" />

    <asp:Parameter Name="original_UnitPrice" Type="Decimal" />

    <asp:Parameter Name="original_UnitsInStock" Type="Int16" />

    <asp:Parameter Name="original_UnitsOnOrder" Type="Int16" />

    <asp:Parameter Name="original_ReorderLevel" Type="Int16" />

    <asp:Parameter Name="original_Discontinued" Type="Boolean" />

    </UpdateParameters>

    <InsertParameters>

    <asp:Parameter Name="ProductName" Type="String" />

    <asp:Parameter Name="SupplierID" Type="Int32" />

    <asp:Parameter Name="CategoryID" Type="Int32" />

    <asp:Parameter Name="QuantityPerUnit" Type="String" />

    <asp:Parameter Name="UnitPrice" Type="Decimal" />

    <asp:Parameter Name="UnitsInStock" Type="Int16" />

    <asp:Parameter Name="UnitsOnOrder" Type="Int16" />

    <asp:Parameter Name="ReorderLevel" Type="Int16" />

    <asp:Parameter Name="Discontinued" Type="Boolean" />

    </InsertParameters>

    </asp:SqlDataSource>

    <br />

    <asp:SqlDataSource ID="Sqldatasource2"

    SelectCommand="Select [SupplierID], [CompanyName] FROM [Suppliers]"

    ConnectionString="Data Source=CONN-SRV2;Initial Catalog=Northwind;Persist Security Info=True;User ID=msol;Password=msol"

    ProviderName="System.Data.SqlClient"

    runat="server" >

    </asp:SqlDataSource>

    <asp:SqlDataSource ID="Sqldatasource3"

    SelectCommand="SELECT [CategoryID], [CategoryName] FROM [Categories]"

    ConnectionString="Data Source=CONN-SRV2;Initial Catalog=Northwind;Persist Security Info=True;User ID=msol;Password=msol"

    ProviderName="System.Data.SqlClient"

    runat="server" >

    </asp:SqlDataSource>

    <asp:SqlDataSource ID="Sqldatasource4"

    SelectCommand="Select [SupplierID], [CompanyName] FROM [Suppliers] where SupplierID=@SupplierID"

    UpdateCommand="Update [Suppliers] set companyName=@CompanyName where SupplierID=SupplierID"

    ConnectionString="Data Source=CONN-SRV2;Initial Catalog=Northwind;Persist Security Info=True;User ID=msol;Password=msol"

    ProviderName="System.Data.SqlClient"

    runat="server" OldValuesParameterFormatString="original_{0}"

    ConflictDetection="CompareAllValues">

    <SelectParameters>

    <asp:SessionParameter Name="SupplierID" SessionField="SupplierID" Type="string" />

    <%-- <asp:Parameter Name="original_CustomerID" Type="string" />--%>

    </SelectParameters>

    <UpdateParameters>

    <asp:Parameter Name="original_SupplierID" Type="Int32" />

    <asp:Parameter Name="CompanyName" Type="string" />

    </UpdateParameters>

    </asp:SqlDataSource>

    <!-- content end -->

    <telerik:Footer runat="server" ID="Footer1"></telerik:Footer>


  3. C7498A83-7E2E-418C-8791-93EF573A7569
    C7498A83-7E2E-418C-8791-93EF573A7569 avatar
    9934 posts
    Member since:
    Nov 2016

    Posted 25 Apr 2007 Link to this post

    Hi Carry,

    Does the sample web site in this thread behaved normally on your end? Note that extending the example may require additional code logic to retain the selected/expanded state of the items in the hierarchy.

    Since the code library section on our site is dedicated to provide custom solutions for the community members and is not aimed as a support resource, I should ask you prepare a stripped working version of your project and send it enclosed to a formal support ticket (which you can start from your Client.net account). I will review your implementation carefully and will get around to you with my findings.

    Regards,
    Stephen
    the telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  4. 05EB1600-F175-45B1-8CA6-30746ACCB0A9
    05EB1600-F175-45B1-8CA6-30746ACCB0A9 avatar
    20 posts
    Member since:
    Apr 2007

    Posted 25 Apr 2007 Link to this post

    hello sir i have sent my problem at support tickets..please fix my problem as soon as possible..i need it urgently..i m not getting any solution
  5. FB22065D-4B15-4D39-BD3F-A8BB39966D78
    FB22065D-4B15-4D39-BD3F-A8BB39966D78 avatar
    1 posts
    Member since:
    Mar 2007

    Posted 06 Sep 2007 Link to this post

    This example is brilliant.  Do you have the source code in VB.NET please?

    Thank you
  6. C7498A83-7E2E-418C-8791-93EF573A7569
    C7498A83-7E2E-418C-8791-93EF573A7569 avatar
    9934 posts
    Member since:
    Nov 2016

    Posted 06 Sep 2007 Link to this post

    Hello Stuart,

    You can easily convert the code logic from the example in VB.NET language using our free online converter:

    http://converter.telerik.com/

    Best regards,
    Stephen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  7. F509B22B-8C62-4F69-964C-B619255FD513
    F509B22B-8C62-4F69-964C-B619255FD513 avatar
    12 posts
    Member since:
    Aug 2007

    Posted 26 Nov 2007 Link to this post

    Hello,

    How should I extend this to  3 level grid. I want to retain the expanded/or not state of the the 3rd level too.

    Thanks.

    Janaki
  8. 54B471F7-6BBB-41C3-8618-C565FA36F636
    54B471F7-6BBB-41C3-8618-C565FA36F636 avatar
    195 posts
    Member since:
    May 2006

    Posted 27 Nov 2007 Link to this post

    From what I learned from this sample I think that you have to create additional ExpandedStates/SelectedStates viewstate properties for the third hierarchy level (and ClearExpandedChildren property respectively). Then track these selected/expanded states with the same method (most probably this will be the approach for n-level hierarchy, too) and restore them on DataBound.

    Bodevain
  9. F509B22B-8C62-4F69-964C-B619255FD513
    F509B22B-8C62-4F69-964C-B619255FD513 avatar
    12 posts
    Member since:
    Aug 2007

    Posted 27 Nov 2007 Link to this post

    Thanks for your reply, Bodevain.

    I managed to get the second level keys into a hastable and can also retrieve it in the databound event. How do I use the information to expand the 2nd level?
     The parent level can be expanded using the code below in your example

    If value Then
        RadGrid1.Items(key).Expanded = True
       End If

    How can I do the same thing for the child level? I tried the following code

    For a = 0 To Grid1.Items.Count - 1
        'Looping thru to check to retrieve the correct parent row
        If Grid1.Items(a).Cells(3).Text = strTransID Then
            Grid1.Items(a).ChildItem.Expanded = True
        End If
    Next

    This does not expand the 3rd level.

    Thanks.
    Janaki

  10. 54B471F7-6BBB-41C3-8618-C565FA36F636
    54B471F7-6BBB-41C3-8618-C565FA36F636 avatar
    195 posts
    Member since:
    May 2006

    Posted 27 Nov 2007 Link to this post

    As far as I know the Items collection of the RadGrid object holds all items in all levels in hierarchical grid (see the description at the bottom of this page). Hence passing valid a index to the Items collection of the grid itself should expand the rows marked for expansion.

    Bodevain
  11. F509B22B-8C62-4F69-964C-B619255FD513
    F509B22B-8C62-4F69-964C-B619255FD513 avatar
    12 posts
    Member since:
    Aug 2007

    Posted 27 Nov 2007 Link to this post

    That clarifies my question to some extent. I would like to know what code I should put in place of the "XXXX" in the sample code from your link.(what is the command I need to use to expand the parent and child rows?)

    For Each item as GridDataItem in RadGrid1.Items
        if item.OwnerTableView.DataMember = "MyDataMember") Then
           If 
                item.OwnerTableView.ParentItem"DataKey").Text =  "some key"                  Then
                            XXXXXXXXXXX
            End If
        end if
    Next

    Thanks.
    Janaki
  12. 54B471F7-6BBB-41C3-8618-C565FA36F636
    54B471F7-6BBB-41C3-8618-C565FA36F636 avatar
    195 posts
    Member since:
    May 2006

    Posted 27 Nov 2007 Link to this post

    In this line of thoughts I presume that the code should continue like this:

    For Each item as GridDataItem in RadGrid1.Items  
        if item.OwnerTableView.DataMember = "MyDataMember"Then 
           If   
                item.OwnerTableView.ParentItem"DataKey").Text =  "some key"                  Then 
                            RadGrid1.Items(<IndexForExpansionFromExpandedStates>). Expanded = True 
                            //more code here  
            End If 
        end if  
    Next 

    Hope this helps.

    Bodevain
  13. F509B22B-8C62-4F69-964C-B619255FD513
    F509B22B-8C62-4F69-964C-B619255FD513 avatar
    12 posts
    Member since:
    Aug 2007

    Posted 27 Nov 2007 Link to this post

    That is what I have for the first level. It expands the parent row to display the child rows but not the grandchildren rows. It probably has to do with the way the detail tables are bound. I have a class that runs different stored procs for each level.

    I'll try some other method of expansion and let you know.

    Thanks for all your help so far.

    Janaki
  14. 2B0222D8-DB7E-4D77-A412-D193ECF6018F
    2B0222D8-DB7E-4D77-A412-D193ECF6018F avatar
    25 posts
    Member since:
    Oct 2007

    Posted 13 Dec 2007 Link to this post

    Did you ever get your grandchildren tables to expand? I am having a similar issue, and have been scrambling for an answer. Thanks!
  15. 54B471F7-6BBB-41C3-8618-C565FA36F636
    54B471F7-6BBB-41C3-8618-C565FA36F636 avatar
    195 posts
    Member since:
    May 2006

    Posted 13 Dec 2007 Link to this post

    Did you give a try the suggestions I posted some time ago? Basically, this should allow you to extend the presented functionality for n-level grid.

    Bodevain

  16. F509B22B-8C62-4F69-964C-B619255FD513
    F509B22B-8C62-4F69-964C-B619255FD513 avatar
    12 posts
    Member since:
    Aug 2007

    Posted 13 Dec 2007 Link to this post

    Yes, I did get it to work.
    I put all the code that actually does the expansion into a seperate subroutine and call it in the Grid PreRender event. Calling the routine in the grid prerender is the key here.

    The subroutine itself has 2 for loops. Parent one for iterating through the keys in the session hashtable. Within that, is another loop for the grid items. There is an If for the datamember.

    For each key as string in arr()
        for each item in grid.items
            if item.datamember = parent level
                if key = uniquecolumnname.value then
                    item.expanded=true
                end if
            elseif item.datamember = childlevel
                    if instr((key,":") then ' hastable is populated as shown below    
                        if partof keyafter ":" = uniquecolumn name.value and 
                            partofkeybefore":"= 
                                    uniquecolumnname.value of ownertable.parentitem
                            item.expanded=true
                        end if
                    end if
            end if
        next
    Next

    The hashtable is populated thus:

    If e.CommandName = RadGrid.ExpandCollapseCommandName Then
        If Not e.Item.Expanded Then
            If InStr(e.Item.ItemIndexHierarchical, ":") Then
                Me.ExpandedStates(e.Item.OwnerTableView.ParentItem.Cells        
                (3).Text & ":" & e.Item.Cells(3).Text) = True
            Else
                Me.ExpandedStates(e.Item.Cells(3).Text) = True
            End If
        Else
                If InStr(e.Item.ItemIndexHierarchical, ":") Then    
                        Me.ExpandedStates.Remove    
                        (e.Item.OwnerTableView.ParentItem.Cells(3).Text & ":" 
                         e.Item.Cells(3).Text)
                Else
                    Me.ExpandedStates.Remove(e.Item.Cells(3).Text)
                End If
        End If
    End If

    Thanks,

    Janaki

  17. 2B0222D8-DB7E-4D77-A412-D193ECF6018F
    2B0222D8-DB7E-4D77-A412-D193ECF6018F avatar
    25 posts
    Member since:
    Oct 2007

    Posted 13 Dec 2007 Link to this post

    That did it, thanks so much!
  18. 738566FD-B834-4D8D-AE86-B27D2F10D7FD
    738566FD-B834-4D8D-AE86-B27D2F10D7FD avatar
    77 posts
    Member since:
    Oct 2007

    Posted 06 Mar 2008 Link to this post

    Does it retain the page index of the detail table?
  19. F509B22B-8C62-4F69-964C-B619255FD513
    F509B22B-8C62-4F69-964C-B619255FD513 avatar
    12 posts
    Member since:
    Aug 2007

    Posted 06 Mar 2008 Link to this post

    I haven't tried it. But I don't think it would support it off the bat. It would need some more customization.
  20. 55399722-08F4-4C16-B02F-AF2E96DF6AC2
    55399722-08F4-4C16-B02F-AF2E96DF6AC2 avatar
    4949 posts
    Member since:
    Jan 2017

    Posted 16 Mar 2010 Link to this post

    Hello,

    We added a slightly modified version of the Web.UI project - it is compatible with the latest versions of RadControls for  ASP.NET AJAX.

    Regards,
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top

This Code Library is part of the product documentation and subject to the respective product license agreement.