Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:



XML
<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>




this is my vb code :

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


thank you in advance
Posted
Updated 22-Aug-13 20:48pm
v2
Comments
vinay.tatipamula 23-Aug-13 3:07am    
If you want to disable Linkbuttons(Select,Edit) for few users, write a itemdatabound event for the gridview and check the condition for which users buttons should be disabled.
Jocelyne El Khoury 23-Aug-13 3:19am    
Thank youuuuu !

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:


C#
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 hope its helping to you.......:-)
 
Share this answer
 
make AutoPostBack="true" and if you want to give user limited access then use Authorization concept...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900