Click here to Skip to main content
11,790,021 members (41,317 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: ASP.NET Entities
Is there a way to add the value from a navigation key on a DataGrid column that is bound to a field from it's Entity container field. This sounds hard to describe!

I have a field that holds a weight, same table has a referenced table for types of weight i.e. lbs, kgs, etc... So I want the column to show 6kg instead of 6.

My first idea:

<asp:BoundColumn DataField="Weight" DataFormatString="{0:<%# Eval("WeightType.WeightType") %>}" HeaderText="Weight ></asp:BoundColumn>

I know illegal as all get out, so is there a way to concatenate this?
Posted 4-Jan-13 15:07pm
Edited 5-Jan-13 14:05pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Just messing around I found you can use the ItemTemplate and add 2 labels, viola! Hope this helps someone else.

                  <asp:label id="lbHeader" runat="server" text="Weight" />
                  <asp:label id="lbWeight" runat="server" text="<%# Bind("Weight") %>" />
                  <asp:label id="lbWeightType" runat="server" text="<%# Bind("Weight.WeightType") %>" />

All I need now is a better title for searches.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 1,029
1 Maciej Los 790
2 KrunalRohit 686
3 CPallini 606
4 Richard MacCutchan 460

Advertise | Privacy | Mobile
Web02 | 2.8.1509028.1 | Last Updated 5 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100