<asp:GridView ID="GVCoresponding" runat="server">
<Columns>
<asp:TemplateField HeaderText="Edit" ShowHeader="false">
<ItemTemplate>
<asp:LinkButton ID="btnedit" runat="server" CommandName="Edit" Text="Edit" ></asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="btnupdate" runat="server" CommandName="Update" Text="Update">
</asp:LinkButton>
<asp:LinkButton ID="btncancel" runat="server" CommandName="Cancel" Text="Cancel">
</asp:LinkButton>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
我的任务
我的网格视图中的所有内容。我想在发生以下情况时隐藏EDIT的LinkButton:
if (Session["dept"].ToString() == "RiskAdmin")
{
????????
}
答案 0 :(得分:1)
您可以将RowDataBound
事件用于此
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
if (Session["dept"].ToString() == "RiskAdmin")
{
LinkButton lnkBtn = (LinkButton)e.Row.FindControl("btnedit");
lnkBtn.Visible = false;
}
}
}