禁用页面加载时的所有链接按钮和复选框
问题描述:
我有一个gridview,它有2个链接按钮:选择和编辑以及1个复选框我需要禁用链接按钮和当某些用户加载页面时的复选框,其他人可以正常看到它们..任何帮助?
这是我的asp页面:
i have a gridview that has 2 link buttons : Select and edit and 1 checkbox i need to disable the link buttons and the checkbox when the page loads for some users and others can see them normally.. any help?
this is my asp page:
<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>
这是我的vb代码:
this is my vb code :
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Session("priv") = "host" Then
fname_txt.Visible = False
lname_txt.Visible = False
email_txt.Visible = False
birthday_txt.Visible = False
phone_txt.Visible = False
adresss_txt.Visible = False
Label2.Visible = False
Label3.Visible = False
Label4.Visible = False
Label5.Visible = False
Label6.Visible = False
Label7.Visible = False
btn_delete.Visible = False
btn_new.Visible = False
Btn_save.Visible = False
End If
If Not IsPostBack Then
GridView1.DataSource = x.selectProfile()
GridView1.DataBind()
End If
End Sub
提前谢谢你
thank you in advance
答
如果你想禁用这些控件你必须在gridview RowDataBoud事件上编写代码因为当我们运行项目时,首先在绑定gridview之前调用此事件。第一件事是如果你想用gridview控件执行一些操作,你必须首先找到控件,之后你将能够访问控件ID并处理它们如下:
IF you want to disable these controls you have to write code on gridview RowDataBoud event becz when we run project this event is called firstly before the bind gridview. and first thing is what if you wants to be perform some opertation with gridview controls you have to find the control firstly after that you will be able to access the control ID and handle them like:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton linkbtn = (LinkButton)e.Row.FindControl("lnkbtn");
linkbtn.Enabled = false;
}
}
i希望它对你有帮助.......: - )
i hope its helping to you.......:-)
make AutoPostBack =true如果你想给用户提供有限的访问权限,那么使用授权概念......
make AutoPostBack="true" and if you want to give user limited access then use Authorization concept...