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

Multiple Child Grids & Selecting Appropriate Row

1 Answer 62 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Richard Weeks
Top achievements
Rank 2
Richard Weeks asked on 16 Aug 2011, 03:17 AM
I have three master /detail RadGrids like:

--1
----2
------3

I am trying to ensure two scenarios:

How can I make sure the appropriate rows are selected and the correct child data loaded for when the page loads and the user clicks a row in any grid?

I tried accessing the SelectedItems during Page_PreRender but only succeeded in selecting the first rows on page load, not when the user clicks a row. I tried the solution found on this site to always select a row but the code did not work for me.

Richard

Here is some source:

aspx
        <telerik:RadGrid 
            AllowAutomaticDeletes="true" 
            AllowAutomaticInserts="true" 
            AllowAutomaticUpdates="true" 
            AutoGenerateEditColumn="true" 
            DataSourceID="FirstDataSource" 
            Height="380" 
            ID="FirstGrid" 
            OnDeleteCommand="Grid_OnCommand" 
            OnInsertCommand="Grid_OnCommand" 
            OnItemDeleted="Grid_OnItemDeleted" 
            OnItemInserted="Grid_OnItemInserted" 
            OnItemUpdated="Grid_OnItemUpdated" 
            OnUpdateCommand="Grid_OnCommand" 
            runat="server">
            <MasterTableView 
                DataKeyNames="Id">
                <Columns>
                    <telerik:GridBoundColumn 
                        DataField="Id" 
                        DataType="System.Int32" 
                        HeaderText="System Id" 
                        ReadOnly="True" 
                        UniqueName="FirstId">
                    </telerik:GridBoundColumn>
                    <telerik:GridButtonColumn 
                        ButtonType="LinkButton" 
                        CommandName="Delete" 
                        ConfirmText="Delete this record?\n\nThis action cannot be undone." 
                        Text="Delete" 
                        UniqueName="DeleteFirst">
                    </telerik:GridButtonColumn>
                </Columns>
            </MasterTableView>
            <ClientSettings 
                AllowKeyboardNavigation="true" 
                EnablePostBackOnRowClick="true">
                <Selecting AllowRowSelect="true" />
                <Scrolling 
                    AllowScroll="true" 
                    SaveScrollPosition="true" 
                    UseStaticHeaders="true" />
            </ClientSettings>
        </telerik:RadGrid>
  
        <telerik:RadGrid 
            AllowAutomaticDeletes="true" 
            AllowAutomaticInserts="true" 
            AllowAutomaticUpdates="true" 
            AutoGenerateEditColumn="true" 
            DataSourceID="SecondDataSource" 
            Height="380" 
            ID="SecondGrid" 
            OnDeleteCommand="Grid_OnCommand" 
            OnInsertCommand="Grid_OnCommand" 
            OnItemDeleted="Grid_OnItemDeleted" 
            OnItemInserted="Grid_OnItemInserted" 
            OnItemUpdated="Grid_OnItemUpdated" 
            OnUpdateCommand="Grid_OnCommand" 
            runat="server">
            <MasterTableView 
                DataKeyNames="Id">
                <Columns>
                    <telerik:GridBoundColumn 
                        DataField="Id" 
                        DataType="System.Int32" 
                        HeaderText="System Id" 
                        ReadOnly="True" 
                        UniqueName="SecondId">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn 
                        DataField="FirstId" 
                        DataType="System.Int32" 
                        ForceExtractValue="Always" 
                        ReadOnly="True" 
                        UniqueName="FirstId" 
                        Visible="false">
                    </telerik:GridBoundColumn>
                    <telerik:GridButtonColumn 
                        ButtonType="LinkButton" 
                        CommandName="Delete" 
                        ConfirmText="Delete this record?\n\nThis action cannot be undone." 
                        Text="Delete" 
                        UniqueName="DeleteSecond">
                    </telerik:GridButtonColumn>
                </Columns>
            </MasterTableView>
            <ClientSettings 
                AllowKeyboardNavigation="true" 
                EnablePostBackOnRowClick="true">
                <Selecting AllowRowSelect="true" />
                <Scrolling 
                    AllowScroll="true" 
                    SaveScrollPosition="true" 
                    UseStaticHeaders="true" />
            </ClientSettings>
        </telerik:RadGrid>
  
        <telerik:RadGrid 
            AllowAutomaticDeletes="true" 
            AllowAutomaticInserts="true" 
            AllowAutomaticUpdates="true" 
            AutoGenerateEditColumn="true" 
            DataSourceID="ThirdDataSource" 
            Height="380" 
            ID="ThirdGrid" 
            OnDeleteCommand="Grid_OnCommand" 
            OnInsertCommand="Grid_OnCommand" 
            OnItemDeleted="Grid_OnItemDeleted" 
            OnItemInserted="Grid_OnItemInserted" 
            OnItemUpdated="Grid_OnItemUpdated" 
            OnUpdateCommand="Grid_OnCommand" 
            runat="server">
            <MasterTableView 
                DataKeyNames="Id">
                <Columns>
                    <telerik:GridBoundColumn 
                        DataField="Id" 
                        DataType="System.Int32" 
                        HeaderText="System Id" 
                        ReadOnly="True" 
                        UniqueName="ThirdId">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn 
                        DataField="SecondId" 
                        DataType="System.Int32" 
                        ForceExtractValue="Always" 
                        ReadOnly="True" 
                        UniqueName="SecondId" 
                        Visible="false">
                    </telerik:GridBoundColumn>
                    <telerik:GridButtonColumn 
                        ButtonType="LinkButton" 
                        CommandName="Delete" 
                        ConfirmText="Delete this record?\n\nThis action cannot be undone." 
                        Text="Delete" 
                        UniqueName="DeleteThird">
                    </telerik:GridButtonColumn>
                </Columns>
            </MasterTableView>
            <ClientSettings>
                <Scrolling 
                    AllowScroll="true" 
                    SaveScrollPosition="true" 
                    UseStaticHeaders="true" />
            </ClientSettings>
        </telerik:RadGrid>
  
    </telerik:RadPane>
</telerik:RadSplitter>
  
<asp:EntityDataSource 
    ConnectionString="name=Entities" 
    DefaultContainerName="Entities" 
    EnableDelete="True" 
    EnableFlattening="False" 
    EnableInsert="True" 
    EnableUpdate="True"  
    EntitySetName="Firsts" 
    EntityTypeFilter="First" 
    ID="FirstDataSource" 
    runat="server">
</asp:EntityDataSource>
  
<asp:EntityDataSource 
    ConnectionString="name=Entities" 
    DefaultContainerName="Entities" 
    EnableDelete="True" 
    EnableFlattening="False" 
    EnableInsert="True" 
    EnableUpdate="True"  
    EntitySetName="Seconds" 
    EntityTypeFilter="Second" 
    ID="SecondDataSource" 
    runat="server" 
    Where="it.[FirstId] = @FirstId">
    <WhereParameters>  
        <asp:ControlParameter ControlID="FirstGrid" DefaultValue="0" Name="FirstId" PropertyName="SelectedValue" Type="Int32" />  
    </WhereParameters>  
</asp:EntityDataSource>
  
<asp:EntityDataSource 
    ConnectionString="name=Entities" 
    DefaultContainerName="Entities" 
    EnableDelete="True" 
    EnableFlattening="False" 
    EnableInsert="True" 
    EnableUpdate="True"  
    EntitySetName="Thirds" 
    EntityTypeFilter="Third" 
    ID="ThirdDataSource" 
    runat="server"
    Where="it.[SecondId] = @SecondId">
    <WhereParameters>  
        <asp:ControlParameter ControlID="SecondGrid" DefaultValue="0" Name="SecondId" PropertyName="SelectedValue" Type="Int32" />  
    </WhereParameters
</asp:EntityDataSource>

1 Answer, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 18 Aug 2011, 12:03 PM
Hello Richard Weeks,

Please note that the Name property of the ControlParameter should match the primary key value added as first to the DataKeyNames array of the corresponding RadGrid. So, I suggest that you modify the data sources in the following way:
<asp:EntityDataSource
    ConnectionString="name=Entities"
    DefaultContainerName="Entities"
    EnableDelete="True"
    EnableFlattening="False"
    EnableInsert="True"
    EnableUpdate="True" 
    EntitySetName="Seconds"
    EntityTypeFilter="Second"
    ID="SecondDataSource"
    runat="server"
    Where="it.[FirstId] = @Id">
    <WhereParameters
        <asp:ControlParameter ControlID="FirstGrid" DefaultValue="0" Name="Id" PropertyName="SelectedValue" Type="Int32" /> 
    </WhereParameters
</asp:EntityDataSource>
   
<asp:EntityDataSource
    ConnectionString="name=Entities"
    DefaultContainerName="Entities"
    EnableDelete="True"
    EnableFlattening="False"
    EnableInsert="True"
    EnableUpdate="True" 
    EntitySetName="Thirds"
    EntityTypeFilter="Third"
    ID="ThirdDataSource"
    runat="server"
    Where="it.[SecondId] = @Id">
    <WhereParameters
        <asp:ControlParameter ControlID="SecondGrid" DefaultValue="0" Name="Id" PropertyName="SelectedValue" Type="Int32" /> 
    </WhereParameters>
</asp:EntityDataSource>

You can use the approach from the Master/Detail Grids demo to make the first and the second grid always have selected rows:
protected void Page_PreRender(object sender, EventArgs e)
{
    if (RadGrid1.SelectedIndexes.Count == 0)
        RadGrid1.SelectedIndexes.Add(0);
    if (RadGrid2.SelectedIndexes.Count == 0)
    {
        RadGrid2.Rebind();
        RadGrid2.SelectedIndexes.Add(0);
    }
}
 
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    RadGrid2.SelectedIndexes.Clear();
}

I hope this helps.

Greetings,
Mira
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Richard Weeks
Top achievements
Rank 2
Answers by
Mira
Telerik team
Share this question
or