簡體   English   中英

如果列為空,如何在gridview中顯示按鈕

[英]How to show button in gridview if a column empty

在我的應用程序中,我只有一個可編輯列,如果該可編輯列為空,我需要顯示添加鏈接按鈕,但它顯示編輯鏈接按鈕。如果gridview中的特定可編輯列為空,如何顯示添加為鏈接按鈕

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

我試過這個,但它正在工作,但無法編輯

最簡單的方法是將添加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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM