Click here to Skip to main content
15,900,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am having one gridview and it's displaying all the data present in table. In that gridview I kept the edit and cancel buttons so my requirement is that edit and cancel button should be available to the employee who booked the room and for other employees the entry should be readonly i.e they should not be able to edit that entry.

Can any one please help me.

Thanks in advance!

C#
private void Validate()
    {
        for (int count = 0; count < gvconference.Rows.Count; count++)
        {
            if (Session["EmployeeId"] == gvconference.Rows[count].Cells[0])
            {
                gvconference.Rows[count].Cells[0].Enabled = false;
            }
            else
                gvconference.Rows[count].Cells[0].Enabled = true;

        }
    }

please check the code i posted tell any changes in that.
Posted
Updated 28-Feb-11 4:10am
v3
Comments
thatraja 28-Feb-11 9:01am    
show your code dude, you can get solutions quickly.

You'll want to study the example on the GridView.RowDataBound event: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx[^].

It is fired by each row as it is supplied with data. You'd want to have a column in your data that shows which user booked the room (column can be hidden in gridview if you don't want to display it). If the currently logged on user is the same one as the one in your data you'll enable the edit and the cancel button. For all other users the buttons will either not be displayed at all or they can just be disabled.

Hope that helps you!
 
Share this answer
 
Comments
Sandeep Mewara 28-Feb-11 10:05am    
Good answer! 5.
mandarapu 28-Feb-11 10:10am    
please check my posted code and help me.
mandarapu 28-Feb-11 10:08am    
please help me with code.
Manfred Rudolf Bihy 1-Mar-11 2:17am    
If the code you gave in your question doesn't have any compilation errors I'd say that it looks good. Have you tried debugging your page?
I always use to handle such situation in markup binding
 <asp:templatefield xmlns:asp="#unknown">
    <itemtemplate>
        <asp:linkbutton id="lblCreateSale" runat="server" commandname="Edit" visible="<%#Eval("BookingUserID").ToString()==CurrentUser %>" text="Edit" />
    </itemtemplate>
</asp:templatefield>

create a property CurrentUser at Codebehind
public string CurrentUser
{
   get
   { 
      //write code to return current user id
   }
}


--Pankaj
 
Share this answer
 
Comments
Manfred Rudolf Bihy 1-Mar-11 2:18am    
Looks usable! 5+

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