我有一个gridview,有2个链接按钮:选择和编辑和1个复选框我需要禁用链接按钮和页面加载时的复选框
这是我的asp页面:
<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代码:
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
提前谢谢你:)
答案 0 :(得分:1)
您需要像这样处理网格的RowDataBound
事件:
标记:
<asp:gridview id="GridView1" onrowdatabound="GridView1_RowDataBound" runat="server">
</asp:gridview>
注意:这告诉GridView
当绑定每一行时,您希望方法GridView1_RowDataBound
处理该事件。
代码隐藏:
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
答案 1 :(得分:0)
最简单的方法是使用设计器中的模板编辑器...转到模板编辑器&gt;单击项目模板,单击链接按钮/复选框,并在属性中将其更改为visible = false。