1

I am using this method to retrieve company from trade. How can I display company ID on GridView? This is my code to retrieve.

public List<Trade> getTrade()
{
    List<Trade> trades=dbContext.trades.Include("tradeCompany")
      .OrderBy(t => t.tradeDate).ToList();

    return trades;
}

I bind to List at code behind... This is my gridview

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
    BackColor="White" OnRowDataBound="sharesGridView_RowDataBound" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" 
    CellPadding="3" GridLines="Vertical">
        <AlternatingRowStyle BackColor="#DCDCDC" />
        <Columns>
            <asp:BoundField DataField="tradeDate" DataFormatString="{0:MMMM d, yyyy}" 
                HeaderText="Date" HtmlEncode="False" SortExpression="tradeDate" />
            <asp:BoundField DataField="type" HeaderText="Type" SortExpression="type" />
            <asp:BoundField HeaderText="Company"  />
            <asp:BoundField DataField="tradePrice" HeaderText="Price" 
                SortExpression="tradePrice" />
            <asp:BoundField DataField="tradeQuantity" HeaderText="Quantity" 
                SortExpression="tradeQuantity" />
        </Columns>
        <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
        <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
        <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
        <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
        <SortedAscendingCellStyle BackColor="#F1F1F1" />
        <SortedAscendingHeaderStyle BackColor="#0000A9" />
        <SortedDescendingCellStyle BackColor="#CAC9C9" />
        <SortedDescendingHeaderStyle BackColor="#000065" />
    </asp:GridView>
1
  • Could you show the markup for your Gridview? How are you binding this list to your GridView? Commented Nov 22, 2011 at 15:40

1 Answer 1

1

Instead of using a BoundField you can use a template field:

<asp:TemplateField>
    <itemtemplate>
        <p><%#DataBinder.Eval(Container.DataItem, "Company.Id")%></p>
    </itemtemplate>
</asp:TemplateField>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.