Ammar Khan
Ammar Khan

Reputation: 356

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?

Upvotes: 2

Views: 809

Answers (2)

Tim Schmelter
Tim Schmelter

Reputation: 460058

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

Upvotes: 2

schei1
schei1

Reputation: 2487

You could hack it doing like Repeater1.DataSource = new List<Movie>() { movie };

Upvotes: 3

Related Questions