开发者

<%# Eval("Name1.Text")%> is empty

<asp:Literal ID="Name1" runat="server">Item Name</asp:Literal>
<asp:LinkButton runat=开发者_JS百科"server" EnableViewState="false" Text='<%#Eval("Name1.Text")%>' />

Why Eval() returns empty ?

Thanks.


You are able to Eval controls that were Databound. If you call Page.DataBind you can eval all controls which NamingContainer is the Page. If you for example DataBind a Gridview, you could eval controls in GridRows.


The time you might want to pass dynamic value as command argument is when it is inside of a databound control.

If it is stand alone control you don't need to pass those values as command argument but simply access them directly inside the Click or OnCommand Event.

If the control is inside of a DataBound control you can set the Command argument in the code-behind.


You could debug it by handling the databinding event of whatever you're trying to databind and taking a look at the variable you're after in that context. Often trying to look at the variable in debug mode will make it very obvious what the problem is.


I don't think that control will be rendered in time.

Do it in code behind.

protected void Page_Init(object sender, Eventargs e)
{    
    lnkButtonID.Text = Name1.Text;   
    lnkButtonID.CommandArgument = Name1.Text; 
}


In fac I would like to do this :

<asp:ImageButton runat="server" ID="addToCartIMG" OnCommand="btnAdd_Click" EnableViewState="false" CommandArgument='<%# itemId1.Value + ";" + Name1.Text %>' ImageUrl="<%$Resources:MasterPage, Image_AddToCart%>" />

where Item1 is hiddenField and Name1 a literal.

When I debug the method btnAdd_Click, the CommandEventArgs is empty.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜