2

我有一个带有 2 个链接按钮的 gridview:选择和编辑和 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

先感谢您 :)

4

2 回答 2

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
于 2013-08-22T15:31:49.093 回答
0

最简单的方法是从设计器中的模板编辑器...转到模板编辑器 > 项目模板,单击链接按钮/复选框并将其更改为可见 = false 在属性中。

于 2013-08-22T15:30:02.817 回答