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

Detail Table Not expanding

2 Answers 242 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Frank
Top achievements
Rank 1
Frank asked on 27 Sep 2012, 08:34 PM
I have a screen with a radgird that has a master table and a detail table.  When I Expand a record that has no detail information the grid expands and shows No Child Record To Display, but when I click on a record that has detail information nothin happens.

<telerik:RadGrid ID="RadGrid1" runat="server" Skin="Office2007" AllowPaging="True" EnableLinqExpressions="false" AllowCustomPaging="true" AutoGenerateColumns="False" GridLines="None" AllowSorting="true" AllowFilteringByColumn="false" AlternatingItemStyle-BackColor="#eeeeee" ShowGroupPanel="False" ShowStatusBar="True" OnNeedDataSource="RadGrid1_NeedDataSource"                                  OnPreRender="RadGrid1_PreRender" OnDetailTableDataBind="HistoryDetail_NeedDataSource">
             <AlternatingItemStyle BackColor="#EEEEEE"></AlternatingItemStyle>
             <MasterTableView DataKeyNames="MarketingID"  PagerStyle-Mode="NextPrevNumericAndAdvanced" >
                    <GroupByExpressions>
                            <telerik:GridGroupByExpression>
                                   <SelectFields>
                                            <telerik:GridGroupByField FieldAlias="ClientName" HeaderText="Client" FieldName="ClientName"
                                                     HeaderValueSeparator=" : "></telerik:GridGroupByField>
                                   </SelectFields>
                      <GroupByFields>
                          <telerik:GridGroupByField FieldName="ClientName" HeaderText="Client" SortOrder="Ascending">
                          </telerik:GridGroupByField>
                      </GroupByFields>
                   </telerik:GridGroupByExpression>
              </GroupByExpressions>
              <RowIndicatorColumn>
                 <HeaderStyle Width="20px"></HeaderStyle>
               </RowIndicatorColumn>
               <ExpandCollapseColumn>
                     <HeaderStyle Width="20px"></HeaderStyle>
               </ExpandCollapseColumn>
                    <Columns>
                           <telerik:GridBoundColumn DataField="MarketingID" HeaderText="MarketingID" SortExpression="MarketingID"  UniqueName="MarketingID" Visible="false">
                           </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="ClientID" UniqueName="ClientID" Visible="false">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="MarketingFormattedID" HeaderText="Marketing ID"
                                       ItemStyle-Width="85" SortExpression="MarketingFormattedID" UniqueName="MarketingFormattedID"
                                        Visible="true" ItemStyle-VerticalAlign="Top">
                             </telerik:GridBoundColumn>
                             <telerik:GridBoundColumn DataField="MarketingTypeName" HeaderText="Marketing Type"
                                              ItemStyle-VerticalAlign="Top" SortExpression="" AllowSorting="false"  UniqueName="MarketingTypeName"        Visible="true">
                             </telerik:GridBoundColumn>
                   </Columns>
                  <PagerStyle Mode="NextPrevNumericAndAdvanced"></PagerStyle>
                                          
                  <DetailTables>
                       <telerik:GridTableView DataKeyNames="MarketingID"  runat="server"  >
                             <ParentTableRelation>
                                     <telerik:GridRelationFields DetailKeyField="MarketingID" MasterKeyField="MarketingID" />
                             </ParentTableRelation>
                             <Columns>
                                    <telerik:GridBoundColumn HeaderText="Status"  DataField="MarketingStatusTypeName" UniqueName="MarketingStatusTypeName">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn  HeaderText="Changed By"  DataField="ChangedBy" UniqueName="ChangedBy">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn HeaderText="Date Changed"  DataField="DateChanged" UniqueName="DateChanged">
                                    </telerik:GridBoundColumn>
                        </Columns>                                                
              </telerik:GridTableView>
         </DetailTables>
      </MasterTableView>
     <ClientSettings AllowDragToGroup="True">
          <Selecting AllowRowSelect="True" />
     </ClientSettings>
     <FilterMenu Skin="Office2007" EnableTheming="True">
          <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
     </FilterMenu>
  </telerik:RadGrid>

and here is the OnDetailTableDataBind Code
protected void HistoryDetail_NeedDataSource(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
        {
  
            GridDataItem dataItem = e.DetailTableView.ParentItem;
  
            ClientDataContext db = new ClientDataContext();
            var query = from m in db.MarketingStatusChangeLogs
                        where (m.MarketingID == int.Parse(dataItem.GetDataKeyValue("MarketingID").ToString()))
                        select new
                        {
                            m.MarketingStatusType.MarketingStatusTypeName,
                            m.ChangedBy,
                            m.DateChanged
                        };
            e.DetailTableView.DataSource = query;
        }


am I missing something?

2 Answers, 1 is accepted

Sort by
0
Accepted
Eric Klein
Top achievements
Rank 1
answered on 28 Sep 2012, 12:46 PM
The issue is in the HistoryDetail_NeedDataSource, you need to include MarketingID in the query.
0
Angel Petrov
Telerik team
answered on 29 Sep 2012, 07:29 AM
Hello Frank,

I have examined the provided code and I think that the problem is in the query. I received and exception in the query saying that LINQ to Entities does not recognize the parse method. Try extracting the MarketingID before the query. Here is a code snippet:
protected void HistoryDetail_NeedDataSource(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
    {
 
        GridDataItem dataItem = e.DetailTableView.ParentItem;
 
        ClientDataContext db = new ClientDataContext();
        int marketingID = int.Parse(dataItem.GetDataKeyValue("MarketingID").ToString());
        var query = from m in db.MarketingStatusChangeLogs
                    where (m.MarketingID == marketingID)
                    select new
                    {
                        m.MarketingStatusType.MarketingStatusTypeName,
                        m.ChangedBy,
                        m.DateChanged
                    };
        e.DetailTableView.DataSource = query;
    }

I am also attaching a sample project which is replicating your scenario.

Regards,
Angel Petrov
the Telerik team
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 their blog feed now.
Tags
Grid
Asked by
Frank
Top achievements
Rank 1
Answers by
Eric Klein
Top achievements
Rank 1
Angel Petrov
Telerik team
Share this question
or