如何显示按钮在gridview如果一列空

本文关键字:如果 一列 gridview 按钮 何显示 显示 | 更新日期: 2023-09-27 18:17:07

在我的应用程序中,我只有一个可编辑的列,如果可编辑列是空的,我需要显示添加链接按钮,但它显示编辑链接按钮。如果gridview中特定的可编辑列为空,我如何将add显示为链接按钮

    <asp:TemplateField>
    <itemtemplate>
         <asp:Button Visible='<%# string.IsNullOrEmpty() %>' runat="server" Text="Edit" ID="Edit" CommandName="Edit" />
         <asp:Button Visible='<%# !string.IsNullOrEmpty() %>' runat="server" Text="Add" ID="Add" CommandName="Edit" />
    </itemtemplate>
</asp:TemplateField>

我试过这个,但它是工作的,但无法编辑

如何显示按钮在gridview如果一列空

最简单的方法是将TemplateField添加到GridView中,并带有2个按钮,这些按钮具有基于列值的可见性。

<asp:TemplateField>
    <itemtemplate>
         <asp:Button Visible='<%# string.IsNullOrEmpty(Eval("editableField").ToString()) %>' runat="server" Text="Edit" ID="Edit" CommandName="Edit" />
         <asp:Button Visible='<%# !string.IsNullOrEmpty(Eval("editableField").ToString()) %>' runat="server" Text="Add" ID="Add" CommandName="Edit" />
    </itemtemplate>
</asp:TemplateField>