Hide label in Formview ASP.NET

陌路散爱 提交于 2019-12-12 04:44:24

问题


I have a "Banned" field in the formview. If the value of this field in false I want to hide the label "From" and "To".

Item template control:

<asp:Label ID="BannedCheckBox" runat="server" Text='<%# DisplayTruthValue(Eval("Banned").ToString())%>' /> &nbsp;
<asp:Label ID="BannedFromLabel" runat="server" Text='<%# "From: " + Eval("BannedFrom")%>'  />&nbsp;
<asp:Label ID="BannedToLabel" runat="server" Text='<%# "To: " + Eval("BannedTo")%>' />

Code behind:

Protected Sub FrmViewPatron_DataBound(sender As Object, e As EventArgs) Handles FrmViewPatron.DataBound
Dim blnBan As String = DirectCast(FrmViewPatron.FindControl("BannedCheckBox"), Label).Text
If blnBan = "False" Then

End If

回答1:


You are already databinding the label so why not set the Visible property the same way. Add Visible='<%# (Eval("Banned") == "True") %>' to both labels, or just Eval("Banned") if it is a boolean field.




回答2:


Try

If blnBan = "False" Then
    FrmViewPatron.FindControl("BannedFromLabel").Visible = False
    FrmViewPatron.FindControl("BannedToLabel").Visible = False
End if 


来源:https://stackoverflow.com/questions/21710259/hide-label-in-formview-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!