[英]How to set the visibility of a control in ASP.NET inside the DataList control?
我有兩個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>
但這是行不通的。 如何正確設置條件? 請幫我。
您可以使用DataList
Item ItemDataBound
事件
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;
}
}
}
並在.aspx
頁上將HiddenField
設為:
<asp:HiddenField ID="hfStatusID" runat="server" Value='<%#Eval("StatusID")%>'/>
嘗試這個:
只需將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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.