title: How can I make RadGrid expand only one detail table based on the command clicked?
body: <p>I have a master view with two child views.  I would like to have command buttons on the master row which cause an expand to happen to one or the other child tables.  When I handle the ItemCommand event, I hide set all detail tables to Visible=False but they are still visible on the output.</p>
  
  <p>I've tried setting the expanded and visibility of the detail tables right within the ItemCommand event like this:</p>
  
  <pre><code>if (e.CommandName == "ExpandSomething")
  {
      item.Expanded = true;
      foreach (var table in MyGrid.MasterTableView.DetailTables)
          if (table.Name != "Something")
              table.Visible = false;
  }
  </code></pre>
  
  <p>This had no effect on the Grid.</p>
  
  <p>Then I thought maybe the hiding needed to be done later in the event cycle so I tried it like this: </p>
  
  <pre><code>private string _activeChildView = null;
  protected void ShowSingleChildTable(string name) //this is called from item command
  {
      _activeChildView = name;
  }
  
  private void Page_PreRender(object sender, EventArgs e)
  {
      if (_activeChildView != null)
          foreach (var table in AdminGrid.MasterTableView.DetailTables)
              if (table.Name != _activeChildView)
                  table.Visible = false;
  }
  </code></pre>
  
  <p>Neither way works - both grids are always visible.</p>
  
  <p>In playing around with different events, I've found that the DataBinding event is the only place that setting the visibility to false works, but unfortunately that fires before the ItemCommand so I can't figure out if a detail button was pressed.</p>
  
  <p>Any other ideas for a conditional detail view like the one described?</p>
  
  <p>EDIT, here's the markup, if you think it'll help.  I've removed the unneeded column definitions:</p>
  
  <pre><code>&lt;asp:EntityDataSource ID="EntityDataSourceThinges" runat="server"
      ConnectionString="name=MyProjectEntities"
      EntitySetName="Thinges" DefaultContainerName="MyProjectEntities"
      EnableDelete="true" EnableUpdate="true" EnableInsert="true"
      Include="ThingSomethings"
      OrderBy="it.Title"
      Where="it.Title like '%' + @Title + '%' or @Title is null"&gt;
      &lt;WhereParameters&gt;
          &lt;asp:ControlParameter ControlID="txtSearch" DefaultValue="%" Name="Title" PropertyName="Text" Type="String" /&gt;
      &lt;/WhereParameters&gt;
  &lt;/asp:EntityDataSource&gt;
  
  &lt;asp:EntityDataSource ID="EntityDataSourceThingSomethings" runat="server"
      ConnectionString="name=MyProjectEntities"
      EntitySetName="ThingSomethings" DefaultContainerName="MyProjectEntities"
      EnableDelete="true" EnableUpdate="true"
      AutoGenerateWhereClause="true"&gt;
      &lt;WhereParameters&gt;
          &lt;asp:SessionParameter Name="ThingID" SessionField="ThingID" Type="Int32" /&gt;
      &lt;/WhereParameters&gt;
  &lt;/asp:EntityDataSource&gt;
  
  &lt;asp:EntityDataSource ID="EntityDataSourceImages" runat="server"
      ConnectionString="name=MyProjectEntities"
      EntitySetName="MyProjectImages" DefaultContainerName="MyProjectEntities"
      EnableDelete="true" EnableUpdate="true" EnableInsert="true"
      AutoGenerateWhereClause="true"
      OrderBy="it.Sequence"&gt;
      &lt;WhereParameters&gt;
          &lt;asp:SessionParameter Name="ThingID" SessionField="ThingID" Type="Int32" /&gt;
      &lt;/WhereParameters&gt;
  &lt;/asp:EntityDataSource&gt;
  
  Search by title:
  &lt;asp:TextBox runat="server" ID="txtSearch" /&gt;&lt;asp:Button runat="server" Text="Search" /&gt;
  
  &lt;telerik:RadGrid ID="DnnGrid1" runat="server"
      DataSourceID="EntityDataSourceThinges"
      ImagesPath="~/images"
      AllowPaging="false" AllowSorting="true" 
      AllowAutomaticUpdates="true" AllowAutomaticInserts="true" AllowAutomaticDeletes="true"&gt;
      &lt;MasterTableView AutoGenerateColumns="false" CommandItemDisplay="TopAndBottom"
          HierarchyLoadMode="ServerOnDemand" ExpandCollapseColumn-Visible="false"
          DataKeyNames="ThingID"&gt;
          &lt;Columns&gt;
              ...
              &lt;telerik:GridButtonColumn Text="Expand Something" CommandName="ExpandSomething" /&gt;
              &lt;telerik:GridButtonColumn Text="Expand Something Else" CommandName="ExpandSomethingElse" /&gt;
              ...
              &lt;telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" ConfirmText="Are you sure you want to permenently delete this record?" /&gt;
          &lt;/Columns&gt;
          &lt;DetailTables&gt;
              &lt;telerik:GridTableView runat="server" Name="Images" DataKeyNames="MyProjectImageID" DataSourceID="EntityDataSourceImages"
                  AutoGenerateColumns="false"
                  AllowAutomaticUpdates="true" AllowAutomaticInserts="true" AllowAutomaticDeletes="true"
                  CommandItemDisplay="TopAndBottom"&gt;
                  &lt;ParentTableRelation&gt;
                      &lt;telerik:GridRelationFields MasterKeyField="ThingID" DetailKeyField="ThingID" /&gt;
                  &lt;/ParentTableRelation&gt;
                  &lt;Columns&gt;
                      ...
                  &lt;/Columns&gt;
              &lt;/telerik:GridTableView&gt;
              &lt;telerik:GridTableView runat="server" Name="Something" DataSourceID="EntityDataSourceThingSomethings"
                  AutoGenerateColumns="false" 
                  AllowAutomaticUpdates="true" AllowAutomaticDeletes="true"
                  CommandItemDisplay="TopAndBottom" DataKeyNames="SomethingID,ThingID"&gt;
                  &lt;ParentTableRelation&gt;
                      &lt;telerik:GridRelationFields MasterKeyField="ThingID" DetailKeyField="ThingID" /&gt;
                  &lt;/ParentTableRelation&gt;
                  &lt;Columns&gt;
                      ...
                  &lt;/Columns&gt;
                  &lt;EditFormSettings EditFormType="AutoGenerated" /&gt;
                  &lt;CommandItemSettings ShowAddNewRecordButton="false" /&gt;
              &lt;/telerik:GridTableView&gt;
          &lt;/DetailTables&gt;
          &lt;EditFormSettings EditFormType="AutoGenerated" /&gt;
      &lt;/MasterTableView&gt;
  &lt;/telerik:RadGrid&gt;
  </code></pre>