我有两个asp:ImageButton。我想在每个表格单元格上隐藏asp:ImageButton ID="ReceiveButton"
,仅在
"<%#Eval("StatusID")=="123" %> "
类似这样的事情
我不知道如何在.ASPX文件中编写这个条件语句。我的代码是这样的。
<td>
<%#Eval("StatusID")%>
</td>
<td align="center">
<asp:ImageButton ID="ReceiveButton" ToolTip="Receive/process this aproved PO" runat="server"
ImageUrl="~/DesktopModules/HBI_PurchaseOrder/Assets/Images/receive.png"
CommandName="CommandReceived" />
<asp:ImageButton ID="DetailButton" ToolTip="View Approved PO" runat="server"
ImageUrl="~/DesktopModules/HBI_PurchaseOrder/Assets/Images/view.png" CommandName="PODetails" />
</td>
我尝试了类似的东西,
<td>
<%#Eval("StatusID")%>
</td>
<td align="center">
<%if (Eval("StatusID") == "123") { %>
<asp:ImageButton ID="ReceiveButton" ToolTip="Receive/process this aproved PO" runat="server"
ImageUrl="~/DesktopModules/HBI_PurchaseOrder/Assets/Images/receive.png"
CommandName="CommandReceived" />
<%} %>
<asp:ImageButton ID="DetailButton" ToolTip="View Approved PO" runat="server"
ImageUrl="~/DesktopModules/HBI_PurchaseOrder/Assets/Images/view.png" CommandName="PODetails" />
</td>
但它不起作用。如何正确设置条件?请帮我。
答案 0 :(得分:1)
您可以使用[{1}}
的项ItemDataBound
事件
DataList
并在protected void DatalistID_ItemDataBound(object sender, DataListItemEventArgs e)
{
HiddenField hfStatusID= e.Item.FindControl("hfStatusID") as HiddenField;
ImageButton ReceiveButton= e.Item.FindControl("ReceiveButton") as ImageButton;
if (hfStatusID!= null && ReceiveButton!=null)
{
if (hfStatusID.Value == "123") // As per your Requirement
{
ReceiveButton.Visible= false;
}
}
}
页上点击HiddenField
:
.aspx
答案 1 :(得分:0)
试试这个:
只需将Visible='<%# Eval("StatusID").ToString().Trim()=="123" %>'
添加到您的控件ReceiveButton
媒体资源中。
<td>
<%#Eval("StatusID")%>
</td>
<td align="center">
<asp:ImageButton ID="ReceiveButton" ToolTip="Receive/process this aproved PO" runat="server"
ImageUrl="~/DesktopModules/HBI_PurchaseOrder/Assets/Images/receive.png"
CommandName="CommandReceived" Visible='<%# Eval("StatusID").ToString().Trim()=="123" %>' />
<asp:ImageButton ID="DetailButton" ToolTip="View Approved PO" runat="server"
ImageUrl="~/DesktopModules/HBI_PurchaseOrder/Assets/Images/view.png" CommandName="PODetails" />
</td>