2
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();

我想在 gridview 中显示选定的字段。如何使用 EVAL 函数呢?还如何使用 DataField 属性?

4

1 回答 1

1

嗨,您可以像使用 ItemTemplate

<asp:GridView ID="GridView1" runat="server">
   <Columns>
    <asp:TemplateField>
        <ItemTemplate>
            <%# Eval("Name")%>
            <br/>
            <%# Eval("Age")%>
        </ItemTemplate>
    </asp:TemplateField>
    </Columns>
</asp:GridView>

或查看以下链接:

http://www.dotnetspider.com/resources/29877-Binding-Gridview-generic-list.aspx

于 2013-03-05T10:36:50.187 回答