简体   繁体   中英

ASP.NET repeater does not contain a definition for repeater

I am trying to create an asp.net table with a repeater. Here is my code for creating the table:

    <table class="pageViewTable" align="centre" border="1">
        <tr bgcolor="green">
            <th>DateTime</th>
            <th>Page</th>
            <th>Location</th>
            <th>IP Address</th>
        </tr>
        <asp:Repeater ID="TableRepeater" runat="server" >       
            <ItemTemplate>
                <tr>
                    <td><%#Container.DataItem("dateTime")%></td>
                    <td><%#Container.DataItem("Page")%></td>
                    <td>::LOCATION</td>
                    <td><%#Container.DataItem("IPAddress")%></td>
                </tr>
            </ItemTemplate>
        </asp:Repeater>     
    </table> 

I have seen many other examples of how to create a repeater in a table but this is the only one that will actually get the page to load.

I then create an arraylist of the class:

public class pageViews
    {
        public string dateTime {get; set;}
        public string IPAddress {get; set;}
        public string Page {get; set;}
        public string Location {get; set;}
    }

and populate it. Next I try to bind the arrylist to the table by:

    TableRepeater.Datasource = pviews;
    TableRepeater.Databind();

Where:

List <pageViews> pviews = new List<pageViews>();

But I get the following error:

 CS1061: 'System.Web.UI.WebControls.Repeater' does not contain a definition for 'Datasource' and no extension method 'Datasource' accepting a first argument of type 'System.Web.UI.WebControls.Repeater' could be found (are you missing a using directive or an assembly reference?)

Here are all my namespaces in the project:

using System;
using System.Web.Configuration; 
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;

I suspect I have a number of errors, but I am not sure what they are.

I have tried numerous tutorials, but cannot seem to get any to work. I am coding in notepad++ please do not suggest to use VS I am trying to learn how to do this with intellisense.

It's DataSource , not Datasource .

I have tried numerous tutorials, but cannot seem to get any to work. I am coding in notepad++ please do not suggest to use VS I am trying to learn how to do this with intellisense.

First of all, you need to read them comprehensively. I doubt that these "numerous tutorials" may be pointing you to a Repeater's Datasource property...

In the other hand, you say don't suggest Visual Studio . Visual Studio isn't just a code editor, but a complete integrated development environment (IDE), and I can't imagine the extra effort you're going to put in to manually compile an ASP.NET application, deploy it, ... In case of .NET solutions, Visual Studio is enough and perfect: there's no advantage on using something like SublimeText, Notepad++ or any other code editor, because you lose a lot of .NET-specific code editing features. One is real-time code error reporting, which would gave you that it's DataSource instead of Datasource .

Most .NET developers won't come to a Q&A site to ask for a wrongly spelled class, property, method or whatever, as Visual Studio will warn you in advance and you'll be more productive!

Also, there's a Visual C# Express, Visual Web Express, now Visual Studio Community (all absolutely free of charge)... Notepad++ is just a waste of time when developing C#, .NET and ASP.NET solutions in Windows.

C#区分大小写,因此应该是DataSource

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM