Asp.net 禁用页面加载上的所有链接按钮和复选框
我有一个gridview,它有两个链接按钮:选择和编辑,以及一个复选框。当页面加载时,我需要禁用链接按钮和复选框 这是我的asp页面:Asp.net 禁用页面加载上的所有链接按钮和复选框,asp.net,vb.net,Asp.net,Vb.net,我有一个gridview,它有两个链接按钮:选择和编辑,以及一个复选框。当页面加载时,我需要禁用链接按钮和复选框 这是我的asp页面: <asp:TemplateField> <ItemTemplate> <asp:CheckBox id="Select" runat="server" OnCheckedChanged="CheckedChanged" AutoPostBack="fa
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox id="Select" runat="server" OnCheckedChanged="CheckedChanged" AutoPostBack="false"/>
<asp:LinkButton ID="idedit" CommandName="Edit" CausesValidation="true" runat="server"
ToolTip="Edit" Text="Edit"/>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="idupdate" CommandName="Update" runat="server" CausesValidation="false" Text="Update"
ToolTip="Update" OnClientClick="javascript:if(!confirm('Are you sure do you want to update this?')){return false;}" />
<asp:LinkButton ID="idcancel" runat="server" CommandName="Cancel" CausesValidation="false"
Text="Cancel" ToolTip="Cancel"/>
</EditItemTemplate>
</asp:TemplateField>
提前感谢:)最简单的方法是使用设计器中的模板编辑器。。。转到模板编辑器>项目模板,单击linkbutton/复选框,并在属性中将其更改为visible=false 您需要像这样处理网格的
RowDataBound
事件:
标记:
<asp:gridview id="GridView1" onrowdatabound="GridView1_RowDataBound" runat="server">
</asp:gridview>
不,因为我有时需要禁用它,有时需要根据身份验证启用它,我不需要一直这样做。。。这取决于身份验证。。。一些用户可以看到链接按钮,而其他用户不能。然后在我的答案中添加条件逻辑,仅当用户是某个角色时才禁用。请参阅更新的答案。如果您觉得此答案对您有帮助,请随时投票选出答案。:-)
<asp:gridview id="GridView1" onrowdatabound="GridView1_RowDataBound" runat="server">
</asp:gridview>
Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
' Only deal with data rows, ignore header rows, footer rows, etc.
If e.Row.RowType = DataControlRowType.DataRow Then
' If the user is a certain role, then do the following logic; otherwise do not
If User.IsInRole("Administrators") Then
' Find the edit link button
Dim theEditLinkButton As LinkButton = CType(e.Row.FindControl("idedit"), LinkButton)
' Disable the edit link button
theEditLinkButton.Enabled = False
End If
End If
End Sub