Search code examples
c#linqdata-bindingrepeater

How can I bind the single LINQ object to ASP.NET Repeater Control


Below is the code snippet which get single record from the database and bind to repeater data source. But when the page render it throws an error

protected void Page_Load(object sender, EventArgs e)
        {

            var movie= context.movies.GetMovie();

            if (!IsPostBack)
            {
                Repeater1.DataSource = movie.;
                Repeater1.DataBind();
            }

        }

Error Message:

An invalid data source is being used for Repeater1. A valid data source must implement either IListSource or IEnumerable.

Any suggestion?


Solution

  • You could make it an array:

    Repeater1.DataSource = new[]{ movie };
    

    But if you always show just a single record i would use a FormView or DetailsView instead.

    Have a look: http://msdn.microsoft.com/en-us/library/ms227992(v=vs.90).aspx