Dr MHQ
Dr MHQ

Reputation: 47

Obout Grid foreign key value Object Data Source

I'm trying to access the foreign key's value I have created a LinqToSQL class where I have relationship between tables is created. I have developed this:

 <asp:ObjectDataSource ID="odsEmp" runat="server" 
    SelectMethod="GetAllEmployees" TypeName="Emp"></asp:ObjectDataSource>
</asp:LinqDataSource>
<cc1:Grid ID="Grid1" runat="server" AutoGenerateColumns="False" 
    DataSourceID="odsEmp" >
    <Columns>
        <cc1:Column DataField="ID" HeaderText="ID" Index="0" ReadOnly="True" 
            Visible="False">
        </cc1:Column>
        <cc1:Column DataField="EmpName" HeaderText="EmpName" Index="1">
        </cc1:Column>
        <cc1:Column DataField="DeptID" HeaderText="Dept" Index="2">
        </cc1:Column>
        <cc1:Column DataField="DeptID" HeaderText="DeptName" Index="6">
        <TemplateSettings TemplateId="templateDeptItem"  />
        </cc1:Column>
    </Columns>
    <Templates>
    <cc1:GridTemplate ID="templateDeptItem">
    <Template>
        <%# Container.DataItem["Dept.DeptName"]%>
    </Template>
    </cc1:GridTemplate>
    </Templates>
</cc1:Grid>

so far I could not retrieve the department name.

support will not respond to me since I'm not using the paid version.

any idea what am I doing wrong ?

I have created another grid using ASP.Net GridView and it worked fine

<asp:GridView ID="GridView1" runat="server" 
    DataSourceID="odsEmp" AutoGenerateColumns="False" 
    AutoGenerateEditButton="True">
    <Columns>
        <asp:BoundField DataField="ID" HeaderText="ID" />
        <asp:BoundField DataField="EmpName" HeaderText="EmpName" />
        <asp:TemplateField HeaderText="Dept">            
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Bind("Dept.DeptName") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

Upvotes: 0

Views: 719

Answers (1)

Dr MHQ
Dr MHQ

Reputation: 47

I have contacted support and got the answer

you'll have to simply use this :

 <cc1:GridTemplate ID="templateDeptItem">
    <Template>
       <%# ((Dept)((Emp)Container.DataObject).Dept).DeptName%>
    </Template>
    </cc1:GridTemplate>

Upvotes: 1

Related Questions