Reputation: 1447
I have a page (default.aspx) with a Repeater fetching data from my database, this is the layout for the Repeater:
default.aspx:
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("Id","~/fullpost.aspx?Id={0}") %>'><asp:Literal ID="LitTitle" runat="server" Text='<%# Eval("Title") %>'></asp:Literal></asp:HyperLink>
<br />
<span class="textSum">
<asp:Literal ID="LitSummary" runat="server" Text='<%# Eval("Summary") %>'></asp:Literal></span>
<span class="dateTime">
<asp:Literal ID="Literal1" runat="server" Text='<%# Eval("CreateDateTime") %>'></asp:Literal></span>
Notice the hyperlink now, it directs to fullpost.aspx, On this page I want to display only that one item I clicked (the URL is being pointed right, it goes to fullpost.aspx?Id=IdNumber), so I tried the following:
fullpost.aspx:
<asp:Literal ID="Literal1" runat="server" Text='<%# Eval("Title") %>'></asp:Literal>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:orangefreshConnectionString1 %>"
SelectCommand="SELECT [Id], [Title], [Summary], [Body], [CreateDateTime] FROM [Post] WHERE ([Id] = @Id)">
<SelectParameters>
<asp:QueryStringParameter Name="Id" QueryStringField="Id" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
But my literal is not displaying the Title as I want it to, nothing shows up. What exactly am I doing wrong here?
After adding the data bound control:
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1">
<asp:Literal runat="server" Text='<%# Eval("Title") %>'></asp:Literal>
</asp:FormView>
I'm now getting: Parser Error Message: Type 'System.Web.UI.WebControls.FormView' does not have a public property named 'Literal'.
Upvotes: 0
Views: 1063
Reputation: 8815
Literal1
on fullpost.aspx is not inside a data bound control to get its data from the SqlDataSource
. Put it inside something like a FormView
with it's data source set to SqlDataSource1
.
EDIT example FormView
The FormView contains a tag called <ItemTemplate>
which contains the controls you want to display. NOTE: If you use an IDE like Visual Web Developer, it will automatically create the correct tag structure for you.
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<asp:Literal runat="server" Text='<%# Eval("Title") %>' />
</ItemTemplate>
</asp:FormView>
Upvotes: 1