在源的可见属性中隐藏gridview超链接而不是后面的代码

时间:2012-07-10 18:39:32

标签: c# asp.net

我有一个带有itemtemplate的gridview,其中包含一个超链接控件。我想隐藏一个超链接控件,如果它在数据库中的项返回null:

  <ItemTemplate>
                                   <asp:HyperLink ID="hlSugar" Visible=<% DataBinder.Eval(Container, "DataItem.CaseID")==null %> ToolTip="View the issue in SugarCRM." Target="_blank" runat="server" NavigateUrl='<%# "http://myPath&record=" + DataBinder.Eval(Container, "DataItem.CaseID") %>' Text="Issue"></asp:HyperLink>
                            </ItemTemplate>

我不确定语法是否可以

Visible = <% iif(databinder.eval(container, "dataItem.caseid")==null, false, true) %>

不确定如何使语法正确。我基本上想检查我的`DataItem.CaseID是否为空,如果是,则隐藏该字段。

4 个答案:

答案 0 :(得分:1)

我最终使用了这个: Visible='<%# Eval("SugarCaseID") != DBNull.Value %>'

答案 1 :(得分:0)

visible='<%# Eval("dataItem.caseid") != null) %>'

试一试

答案 2 :(得分:0)

你可以这样做

bool ShowLink(obj data)
{ 

   if(data!=null) {return true; } return false;
}

ASPX:

<asp:HyperLink ID="hlSugar" Visible='<%# ShowLink(Eval("CaseID"))%>' 
 ToolTip="View the issue in SugarCRM." Target="_blank" runat="server" 
 NavigateUrl='<%# "http://myPath&record=" 
 + DataBinder.Eval(Container, "DataItem.CaseID") %>' Text="Issue">
</asp:HyperLink>

答案 3 :(得分:0)

使用此

<asp:HyperLink ID="hlSugar" Visible='<%# Convert.ToBoolean(Eval("DataItem.CaseID").ToString() == "0") %>' ToolTip="View the issue in SugarCRM." Target="_blank" runat="server" NavigateUrl='<%# "http://myPath&record=" + DataBinder.Eval(Container, "DataItem.CaseID") %>' Text="Issue" />

参考: Conditions within .aspx file for ListView ItemTemplate