Click here to Skip to main content
15,913,279 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I want to display records in a gridview.

Now, the condition is that the logged in user can see all the information but can only delete his own records.

I am not getting the main logic!

Hope someone could help!

Thanks
Posted

1 solution

I think in gridview you would have any field like username or ID that you can match with the session of logged in user. To disable the delete right for other you can hide delete button of other rows in your gridview in following way

C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
 {
    if (e.Row.RowType == DataControlRowType.DataRow)
     {
        if (!DataBinder.Eval(e.Row.DataItem, "Column_Of_UserName").Equals(Session["User"].ToString()))
          {
              LinkButton btn = (LinkButton)e.Row.Cells[Indext of your commandfield column].Controls[0];
              if (btn != null)
               {
                    btn.Visible = false;
               }
          }
    }
}
 
Share this answer
 
v4
Comments
Ahsan Mirza 20-Jul-11 5:25am    
actually brother i am not getting your idea as i am using command-field for delete, edit and update.
Raju Prajapati 20-Jul-11 7:38am    
Ok, if you are using command-field then you can hide the autogenerated linkbuttons(edit, update, delete) of commandfield for all other rows those rows are not related with logged in user
(actually i wanted to tell that you should hide the buttons that controls delete action for the rows of all other details those are not related to logged in user)
Ahsan Mirza 20-Jul-11 8:10am    
It gives the following error: Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.LinkButton'.

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