前端:
<asp:GridView ID="grvDictList" runat="server" GridLines="None" AutoGenerateColumns="False" EmptyDataText="数据为空" OnRowDataBound="grvDicList_RowDataBound" > <Columns> <asp:TemplateField HeaderText="操作" > <ItemTemplate> <asp:Button ID="btnDelete" CssClass="btn anniu1 btn-sm" OnClick="btnDelete_Click" CommandArgument=‘<%#Eval("fID")%>‘ runat="server" Text="删除" /> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>
后端
protected void grvDicList_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if (我满足判断条件) { Button lb = e.Row.FindControl("btnDelete") as Button; //Button:网页上显示的按钮控件。 //FindControl(string id):指定的服务器控件当前命名容器中搜索id参数,返回结果为null则指定控件不存在。 //如果是asp:LinkButton 控件, 就 LinkButton lb=e.Item.FindControl("btnDelete") as LinkButton; if (lb != null) { lb.Visible = false; } } } }