2

我有一个 gridview gvData 我想要的是当 TransType 列中的记录等于甜点然后显示写入,RT。如果它有任何其他的唯一显示关闭编辑删除。

关闭 编辑 删除 写入 RT 在模板字段中

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>

4

2 回答 2

1

在您的 上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;
                }
            }
于 2013-08-01T18:24:57.323 回答
1

在过去,我制作了一个代码隐藏方法来评估并返回一个布尔值。

protected bool IsTransTypeDessert(string transType)
{
    return transType.ToLower() == "dessert";
}

然后在标记中,像这样调用该方法:

<asp:LinkButton ID="lbWrite" runat="server" CausesValidation="False" CommandName="WriteClicked" OnClick="Write_Click"
Visible='<%# IsTransTypeDessert(Eval("TRANSTYPE") != null ? Eval("TRANSTYPE").ToString() : "") %>'>Write</asp:LinkButton>

我不记得的一件事是是否IsTransTypeDessert需要返回“true”或“false”的字符串表示,或者布尔是否可以工作。测试将确定它。

于 2013-08-01T18:28:40.310 回答