gpt4 book ai didi

asp.net - Gridview 中的条件删除按钮

转载 作者:行者123 更新时间:2023-12-04 05:30:38 25 4
gpt4 key购买 nike

我的 gridview 中有一个删除按钮,但我希​​望这个按钮不能根据 sql 查询的结果工作。

一个例子

我有一个带有“运送容器”的 GridView ,我想从这个列表中删除一个容器,但我想显示一条消息“要能够删除这个容器,请从产品中删除它”,这样如果一个船舶容器正在使用中,我需要防止它被删除。

最佳答案

这是您可以执行此操作的方法:

<asp:GridView ID="EntityGridView" runat="server" DataKeyNames="DocumentId" AutoGenerateColumns="False"
AllowPaging="True" AllowSorting="False" SkinID="GridViewSmall" OnRowCommand="EntityGridView_RowCommand"
OnPageIndexChanged="EntityGridView_PageIndexChanged">
<Columns>
<asp:TemplateField ItemStyle-CssClass="TemplateFieldThreeColumns">
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" ImageAlign="Top" runat="server" ImageUrl='<% #ResolveImageUrl(Eval("Extension").ToString()) %>'
ToolTip='<%# Eval("Extension").ToString() %>' CommandName="Select" CommandArgument='<%# Eval("DocumentId") %>' />
<asp:ImageButton ID="btnDelete" runat="server" ToolTip="<% $resources:AppResource,Delete %>"
SkinID="DeletePage" OnClientClick="<%# GetDeleteConfirmation(Resources.AppResource.ConfirmDocumentDelete) %>"
CommandName="CustomDelete" CommandArgument='<%# Eval("DocumentId") %>' Visible='<% #AllowDocDelete(Container.DataItem) %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Title" HeaderText="<% $resources:AppResource,Title %>" />
<asp:BoundField DataField="Author" HeaderText="<% $resources:AppResource,Author %>" />
<asp:BoundField DataField="FileName" HeaderText="<% $resources:AppResource,FileName %>" />
<asp:BoundField DataField="Created" HeaderText="<% $resources:AppResource,Created %>" />
</Columns>
<EmptyDataTemplate>
<asp:Label ID="EmptyLabel" runat="server" Text='<%# Resources.AppResource.NoContentToDisplay %>' CssClass="NoDataLabel"></asp:Label>
</EmptyDataTemplate>
</asp:GridView>

注意禁用删除按钮的 AllowDocDelete 函数。这个函数应该在你的页面类中声明,如下所示:
    public bool AllowDocDelete(object item)
{
bool result = false;
//TODO: check your condition
return result;
}

Item 对象表示绑定(bind)的实体。

关于asp.net - Gridview 中的条件删除按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12669340/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com