Click here to Skip to main content
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 9: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 271
1 OriginalGriff 223
2 nv3 50
3 VJ Reddy 45
4 Mehdi Gholam 45
0 Sergey Alexandrovich Kryukov 6,696
1 OriginalGriff 6,149
2 CPallini 2,473
3 Richard MacCutchan 1,697
4 Abhinav S 1,560


Advertise | Privacy | Mobile
Web01 | 2.8.140821.2 | Last Updated 4 Jul 2014
Copyright © CodeProject, 1999-2014
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