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

Binding to more than one table using TreeList

1 Answer 93 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 11 Jun 2012, 07:03 PM

I am new to Telerik and I am trying to set up a TreeList that binds to an ObjectDataSource, which gets its data from LINQ.  The primary LINQ entity is Matter; every matter has an associated Client record.

For the TreeList, Client would be the parent and Matter would be the child.

The problem is, Clients and Matters are in different tables.  Can I build out a TreeList programatically like I can a TreeView with nodes?  Is there an easier way?

The Client/Matter relationship is defined as an association in LINQ.

---UPDATE---

I've bound ListView to an ObjectDataSource that combines the two tables together.  It isn't returning any data, however.  Any idea what I am doing wrong?  Again, Clients contain Matters.  A record will be unique for each Matter but will contain non-unique data for its parent, Client.

<asp:ObjectDataSource ID="ClientMattersOds" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetMattersBilledInPastYear" TypeName="Data.ClientMatter">
    <SelectParameters>
        <asp:Parameter Name="emplUno" Type="Int32" DefaultValue="66" />
    </SelectParameters>
</asp:ObjectDataSource>
 
<telerik:RadTreeList ID="ClientsMattersTreeList" runat="server" DataKeyNames="MatterUno" ParentDataKeyNames="ClientUno" DataSourceID="ClientMattersOds"
    PageSize="25" OnNeedDataSource="ClientsMattersTreeList_NeedDataSource" OnDataBound="ClientsMattersTreeList_DataBound">
<ExportSettings ExportMode="RemoveControls">
<Excel PageLeftMargin="0.7in" PageRightMargin="0.7in"></Excel>
 
<Pdf PageWidth="8.5in" PageHeight="11in"></Pdf>
</ExportSettings>
 
<EditFormSettings EditFormType="AutoGenerated">
<EditColumn MinWidth="" MaxWidth=""></EditColumn>
</EditFormSettings>
    <Columns>
        <telerik:TreeListBoundColumn DataField="CLIENT_UNO" DataType="System.Int16" MaxWidth="" MinWidth="" UniqueName="column">
        </telerik:TreeListBoundColumn>
    </Columns>
</telerik:RadTreeList>


[DataObjectMethod(DataObjectMethodType.Select, true)]
public static List<ClientMatter> GetMattersBilledInPastYear(int emplUno)
{
    var dc = new Data.DdDataContext();
 
    //Get the matters by searching all the time entries for this timekeeper from the past year
    //Select only the resulting records that match records from this class
    var records = dc.TimeEntries.Where(a => a.TK_EMPL_UNO == emplUno).Select(a => new ClientMatter()
        {
            _matter_Uno = a.MATTER_UNO,
            _client_Uno = a.Matter.CLIENT_UNO,
            _matter_Code = a.Matter.MATTER_CODE,
            _client_Code = a.Matter.Client.CLIENT_CODE,
            _matter_Name = a.Matter.MATTER_NAME,
            _client_Name = a.Matter.Client.CLIENT_NAME
        }).Distinct().ToList();
 
    return records;
}

1 Answer, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 14 Jun 2012, 07:57 AM
Hello,

 Please try removing the OnNeedDataSource event in the TreeList. You should either bind it to an ObjectDataSource in the markup or programmatically using the NeedDataSource event, but not with both.

Kind regards,
Marin
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
TreeList
Asked by
Mark
Top achievements
Rank 1
Answers by
Marin
Telerik team
Share this question
or