看了一些例子,发现GridView都是绑定到datareader、dataset、xml数据等等,
难道不能绑定到一个List<>泛型列表吗?
请指教!

解决方案 »

  1.   

    绑定一个List<T>是可以的,像绑定DataSet一样的操作就可以了,但对于列的字段名,应该是T的可读写属性或字段
      

  2.   

    谢谢指教
    但是我在给定数据源的时候,报错:
    ID 为“GridView1”的 GridView 的数据源没有任何可用来生成列的属性或特性。请确保您的数据源有内容。 代码如下(可以肯定的是currentVersion.BusLineList是有内容的):
    this.GridView1.DataSource = currentVersion.BusLineList;
    this.GridView1.DataBind();前台如下:
    <asp:GridView ID="GridView1" runat="server">
                    <Columns>
                       <asp:TemplateField>
                            <ItemTemplate>
                                <span style="float:left">线路名称:<%#Eval("名称") %></span>
                                <span style="float:right;color:Red;cursor:pointer" onclick="ShowHidden('<%#Eval("标识") %>',event)">隐藏</span>
                            </ItemTemplate>
                       </asp:TemplateField>
                    </Columns>
                </asp:GridView>
      

  3.   

    <%# Container.DataItem.ToString() %>可以用這個綁定