Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.NET
<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
Updated 5-Jan-13 14:05pm
v2

1 solution

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

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


All I need now is a better title for searches.
 
Share this answer
 
v3

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900