Hi,
I am currently working through Beginning ASP.NET 4.5, and have encountered a problem when going through the Try It Out that begins on pg. 513.
When switching to Design View in step 5, the repeater control has a message saying
"Error creating control-Repeater1
The DataSource cannot be set declaratively."
Attempting to compile leads to an error with the same "DataSource cannot be set declaratively" message, that when clicked highlights the BulletedList in AllByGenre.aspx file.
Below is the code for both AllByGenre.aspx and AllByGenre.aspx.
vb.
Many thanks in advance to anyone who helps out a struggling newb!
Code:
<%@ Page Title="Reviews Grouped by Genre" Language="VB" MasterPageFile="~/MasterPages/Frontend.master" AutoEventWireup="false" CodeFile="AllByGenre.aspx.vb" Inherits="Reviews_AllByGenre" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<h3><asp:Literal ID="Literal1" runat="server" Text='<&# Eval("Name") %>'></asp:Literal></h3>
<asp:BulletedList ID="ReviewList" runat="server" DataSource='<&# Eval("Reviews") %>' DataTextField="Title" DisplayMode="Text"></asp:BulletedList>
</ItemTemplate>
</asp:Repeater>
</asp:Content>
Code:
Imports PlanetWroxModel
Partial Class Reviews_AllByGenre
Inherits BasePage
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Using myEntities As New PlanetWroxEntities()
Dim allGenres = From genre In myEntities.Genres.Include("Reviews")
Order By genre.Name
Select New With {genre.Name, genre.Reviews}
Repeater1.DataSource = allGenres
Repeater1.DataBind()
End Using
End Sub
End Class