Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i wrote this code and get this error
An ItemTemplate must be defined on ListView 'ListView1'.

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


what can i do ?
Posted
Comments
Sergey Alexandrovich Kryukov 22-Feb-13 15:36pm    
Well, Captain Obvious says: define ItemTemplate:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview.itemtemplate.aspx,
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview.aspx.

Search for ItemTemplate in the second article referenced above, to see how to use it.

—SA

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
 
Share this answer
 
XML
<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>




C#
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();
       }
   }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900