Use of <%= %> and expression databinding for Write Response
i want write content(summary) with <%= %> and expression databinding in below code but do开发者_高级运维 not success!how i can, do it?
<asp:Literal Text='<%# Eval("Summary") %>' ID="SumLitteral" runat="server" />
if you use # sign
with the binding expression, then you need to call DataBind()
method..
protected void Page_PreRenderComplete(object sender, EventArgs e)
{
DataBind();
}
You can't use the <%= %> syntax to set a property in a server control. You can only use a databinding expression, which you actually have already in your example. Assuming this is part of a Repeater (or some other templated control) and the DataSource is made up of items that have a Summary property, your code above would work. If it's not part of a repeater you can still use a databinding expression, but Eval("Summary") would not have a meaning that makes sense to me, in that case.
If you're saying that the "Summary" value is not actually displaying, its likely that databind() is not being called on the page or the control.
精彩评论