Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net bind a list to a gridview

Tags:

c#

asp.net

List<MasterBook> listOfBooks = new List<MasterBook>();

after i put the masterbook objects which by the way have 3 fields( name,id and active ) into the list

 GridView1.DataSource = listOfBooks;
 GridView1.DataBind(); 

in the web form

   <Columns>

            <asp:TemplateField HeaderText="Book Name">
                <ItemTemplate>
                    <asp:Label ID="BookNameText" runat="server" 
                            Text="<%#Container.DataItem%>">

                    </asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>

    </asp:GridView>

the problem is that i want to display the bookmaster's name in the gridview column this code print bookmaster in the column how can i make it type the name

like image 731
user2401745 Avatar asked Jun 17 '13 13:06

user2401745


1 Answers

Change:

  <%#Container.DataItem%>

To:

  <%#Eval("name")%>
like image 96
hutchonoid Avatar answered Sep 29 '22 09:09

hutchonoid