\' /> Error: Compiler Error Message: CS1525: In开发者_JAVA百科valid expression term \'," />
开发者

Asp.Net(C#) inline coding Eval if statement problem

开发者 https://www.devze.com 2022-12-28 06:10 出处:网络
<%# Eval(\"NAME\").ToString() == \"Edit\" ? %> \' /> Error: Compiler Error Message: CS1525: In开发者_JAVA百科valid expression term \',

<%# Eval("NAME").ToString() == "Edit" ? %> ' />

Error: Compiler Error Message: CS1525: In开发者_JAVA百科valid expression term ',

How to make please help me?

Thank you all;


This will do:

<asp:ImageButton ID="imgEdit" runat="server" ImageUrl="../icons/icoedit.png" CommandName="Edit" Visible='<%# Convert.ToBoolean(Eval("NAME").ToString() == "Edit") %>' CommandArgument='<%# Container.DataItemIndex %>' />


The ? on the end looks like you are going for a ternary operator but you haven't finished it off.

Personally in this situation I like to use the visible property like:

<asp:ImageButton ID="imgEdit" runat="server" ImageUrl="../icons/icoedit.png" 
CommandName="Edit" Visible='<%# Eval("NAME").ToString() == "Edit" %>' 
CommandArgument='<%# Container.DataItemIndex %>' />

Or if you want the opposite

<asp:ImageButton ID="imgEdit" runat="server" ImageUrl="../icons/icoedit.png" 
CommandName="Edit" Visible='<%# Eval("NAME").ToString() != "Edit" %>' 
CommandArgument='<%# Container.DataItemIndex %>' />
0

精彩评论

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

关注公众号