gpt4 book ai didi

c# - 根据条件启用/禁用 Gridview 中的链接按钮

转载 作者:太空宇宙 更新时间:2023-11-03 11:00:06 25 4
gpt4 key购买 nike

我有一个 gridview gvData 我想要的是当 TransType 列中的记录等于 Dessert 然后显示 Write,RT。如果还有其他问题,则只显示关闭编辑删除。

Close Edit Delete Write RT are in a Template Field

ID    TRANSTYPE    R      C     TIME    
1 Dessert 12:00 12:05 12 Close Edit Delete Write RT


<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="lbClose" runat="server" CausesValidation="False" CommandName="CloseClicked" OnClick="CloseClick_Click">Close</asp:LinkButton>
<asp:LinkButton ID="lbEdit" runat="server" CausesValidation="False" CommandName="EditRow" OnClick="Edit_Click" CommandArgument='<%# Eval("Id")%>'>Edit</asp:LinkButton>
<asp:LinkButton ID="lbDelete" runat="server" CausesValidation="False" CommandName="DeleteRow"OnClick="Delete_Click" OnClientClick="return confirm('Are you sure you want to Delete this Transaction?');">Delete ||</asp:LinkButton>
<asp:LinkButton ID="lbWrite" runat="server" CausesValidation="False" CommandName="WriteClicked" OnClick="Write_Click">Write</asp:LinkButton>
<asp:LinkButton ID="lbRT" runat="server" CausesValidation="False" CommandName="RT"OnClick="RT_Click">RT</asp:LinkButton>
</ItemTemplate>

最佳答案

在您的 gvData _OnRowDataBound 上,检查条件并将每行的相应按钮 Visible 属性设置为 false。

            protected void gvData_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
LinkButton lbClose = (LinkButton)e.Row.Cells[5].FindControl("lbClose");
LinkButton lbEdit = (LinkButton)e.Row.Cells[5].FindControl("lbEdit");
LinkButton lbDelete = (LinkButton)e.Row.Cells[5].FindControl("lbDelete");
LinkButton lbWrite = (LinkButton)e.Row.Cells[5].FindControl("lbWrite");
LinkButton lbRT = (LinkButton)e.Row.Cells[5].FindControl("lbRT");

if(e.Row.Cells[1].Text=="Dessert")
{
lbClose.Visible = false;
lbEdit.Visible = false;
lbDelete.Visible = false;
}
else
{
lbWrite.Visible = false;
lbRT.Visible = false;
}
}

关于c# - 根据条件启用/禁用 Gridview 中的链接按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18001632/

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