2012-07-10 51 views
0

我得到了一个带有超链接控件的itemtemplate的gridview。我想隐藏的超链接控制,如果它在数据库中的项目空返回:在源代码的可见属性中隐藏gridview超链接,而不是在后面的代码

<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是否为空,如果它是隐藏此字段。

回答

1

我结束了使用此: Visible='<%# Eval("SugarCaseID") != DBNull.Value %>'

0

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

这给了一枪

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> 
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