Click here to Skip to main content
11,489,693 members (67,135 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 ?
Posted 22-Feb-13 10:32am
Comments
Sergey Alexandrovich Kryukov at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

<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();
       }
   }
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 535
1 OriginalGriff 223
2 Andy Lanng 193
3 Maciej Los 190
4 _duDE_ 141
0 Sergey Alexandrovich Kryukov 9,488
1 OriginalGriff 8,425
2 Sascha Lefèvre 3,344
3 Maciej Los 3,066
4 Richard Deeming 2,370


Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 4 Jul 2014
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100