Reputation: 87
Client side:
<asp:Repeater ID="QuestionRepeater" runat="server">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li><%# Eval("Question_Question") %></li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
Code Behind:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindRepeater();
}
}
private void BindRepeater()
{
var q = from u in db.tbl_Question select u.Question_Question;
QuestionRepeater.DataSource = q.ToList();
QuestionRepeater.DataBind();
}
Error:
Error is on line where use use Eval("Question_Question")
function, i also tried Bind("Question_Question")
.
DataBinding: 'System.String' does not contain a property with the name 'Question_Question'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: DataBinding: 'System.String' does not contain a property with the name 'Question_Question'.
Upvotes: 0
Views: 60
Reputation: 14677
You're binding the repeater to list of strings. Change the binder expression to:
<ItemTemplate>
<%# Container.DataItem?.ToString() ?? string.Empty%>
</ItemTemplate>
Upvotes: 3