列表视图数据源中的错误 [英] error in list view datasource

查看:75
本文介绍了列表视图数据源中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了这段代码并得到了这个错误

必须在ListView的'ListView1'上定义ItemTemplate。



i wrote this code and get this error
An ItemTemplate must be defined on ListView 'ListView1'.

var data = from Student p in db.Students select p;
this.ListView1.DataSource = data;
ListView1.DataBind();





我该怎么办?



what can i do ?

推荐答案

嗨哥们



此链接将帮助您,因为抛出相同的错误,您解决了....



http://stackoverflow.com/questions/12904570/ dynamic-load-listview-template-from-ascx [ ^ ]



仔细阅读



乐意help
Hi buddy

this link will help you because throwing the same error that you getting with solved....

http://stackoverflow.com/questions/12904570/dynamic-load-listview-template-from-ascx[^]

read that carefully

Happy to help


<body>
    <form id="form1" runat="server">
    <div>
        <asp:DataList ID="DataList1" runat="server" Width="197px" BackColor="#DEBA84"

            BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3"

            CellSpacing="2" GridLines="Both">
            <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
            <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
            <ItemStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
            <ItemTemplate>
               <asp:Label ID="w" runat="server" Text='<%#Eval("id") %>'></asp:Label>
               <asp:Label ID="Label1" runat="server" Text='<%#Eval("name") %>'></asp:Label>
               <asp:Label ID="Label2" runat="server" Text='<%#Eval("address") %>'></asp:Label>
            </ItemTemplate>
            <SelectedItemStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
        </asp:DataList>
    </div>
    </form>
</body>













protected void Page_Load(object sender, EventArgs e)
   {
       if (!IsPostBack)
       {
           DataClassesDataContext dcx = new DataClassesDataContext();
           var data = from c in dcx.TESTs
                      select c;
           DataList1.DataSource = data;
           DataList1.DataBind();
       }
   }


这篇关于列表视图数据源中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆