Reputation: 19
List<Person> pList = new List<Person>();
pList.Add(new Person(1, "John", "", "Shields", 29, 'M'));
pList.Add(new Person(2, "Mary", "Matthew", "Jacobs", 35, 'F'));
pList.Add(new Person(3, "Amber", "Carl", "Agar", 25, 'M'));
pList.Add(new Person(4, "Kathy", "", "Berry", 21, 'F'));
pList.Add(new Person(5, "Lena", "Ashco", "Bilton", 33, 'F'));
pList.Add(new Person(6, "Susanne", "", "Buck", 45, 'F'));
pList.Add(new Person(7, "Jim", "", "Brown", 38, 'M'));
pList.Add(new Person(8, "Jane", "G", "Hooks", 32, 'F'));
pList.Add(new Person(9, "Robert", "", "", 31, 'M'));
pList.Add(new Person(10, "Cindy", "Preston", "Fox", 25, 'F'));
pList.Add(new Person(11, "Gina", "`enter code here`", "Austin", 27, 'F'));
pList.Add(new Person(12, "Joel", "David", "Benson", 33, 'M'));
pList.Add(new Person(13, "George", "R", "Douglas", 55, 'M'));
pList.Add(new Person(14, "Richard", "", "Banks", 22, 'M'));
pList.Add(new Person(15, "Mary", "C", "Shaw", 39, 'F'));
gv1.DataSource = pList;
gv1.DataBind();
I want to display selected fields in the gridview. How to use EVAL function with it? ALso How to use DataField Property with it?
Upvotes: 2
Views: 203
Reputation: 482
Hi you can use ItemTemplate as like
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<%# Eval("Name")%>
<br/>
<%# Eval("Age")%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
or see following link :
http://www.dotnetspider.com/resources/29877-Binding-Gridview-generic-list.aspx
Upvotes: 1