-1

可能重复:
想要根据 Gridview 字段中的值启用图像按钮

如果状态 = 1,我想禁用 gridview 删除按钮。1 表示已删除。我正在使用以下代码禁用删除按钮,它返回错误消息“服务器标签格式不正确。”。

 <asp:TemplateField ItemStyle-Width="20px" HeaderImageUrl="~/images/icn_trash.png" >
  <ItemTemplate>
     <asp:ImageButton ID="btn_delete" runat="server" Enabled="<%# (Eval("fld_status").ToString()=="0") ? "true" : "false" %>" ToolTip="Delete" OnClientClick="return confirm('Important Alert : Do you delete this item ?')" CommandName="del" CommandArgument='<%#Bind("fld_val_id") %>' ImageUrl="~/images/icn_trash.png" />
   </ItemTemplate>
  <ItemStyle Width="20px"></ItemStyle>
</asp:TemplateField>
4

3 回答 3

0

Try escaping the quotes

Enabled="<%# (Eval(\"fld_status\").ToString()=="0") ? "true" : "false" %>"

you could also use single quotes like you did here

CommandArgument='<%#Bind("fld_val_id") %>'
于 2012-12-05T12:07:27.270 回答
0

I assume you should use ' here:

Enabled='<%# (Eval("fld_status").ToString()=="0") ? "true" : "false" %>'
于 2012-12-05T12:07:53.963 回答
0

Replace the " with ' and remove the "" around the booleans:

Enabled='<%# (Eval("fld_status").ToString()=="0") ? true : false %>'
于 2012-12-05T12:08:12.917 回答