2

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?

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you very much. That's work. The reason for using repeater for a because I wan to have custom html markup on the page. I found out other data controls produce tables when they render. I want to have custom defined markup appear on the view source. Do you have better suggestion?
@user2866746: as mentioned in my answer you can use a FormView or DetailsView instead. The difference is that the DetailsView produces the (undesired) tabular layout whereas the FormView gives you full control. You create a template that contains controls to display individual fields from the record similar to the repeater.
I would probably used a FormView or DetailsView like suggested by @TimSchmelter, or implemented a custom view for viewing the details.
If I use form view Can I directly bind a single linq object to it's data source?
@user2866746: No, the DataSource property of every databound WebControl in ASP.NET needs to implement either IListSource or IEnumerable even if it displays just a single record. That's illogical but not a problem because you can use our workarounds.
2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.