Click here to Skip to main content
16,012,168 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want a grid view to show command field(edit, delete) against those records only
which are owned by the user that is currently logged-in.

Thanks!
Posted
Updated 20-Jul-11 0:48am
v2

1 solution

in the onRowDataBoundEvent of the gridview you can retrieve the DataRowView. If the userid is in the data (even if that field is not shown in your gridview!) you can then check if the userid is the same as the logged in user.
Than do a findControl on the gridviewrow and set the control to visible = true or false.

in my example a tooltip is added to an image based on a value in the DataRowView.

protected void grdAppSettingsORDB(Object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType.Equals(DataControlRowType.DataRow))
        {
            DataRowView dataRow = (DataRowView)e.Row.DataItem;
            Image imgHelp = (Image)e.Row.FindControl("imgHelp");
            if (null != imgHelp)
            {
                imgHelp.ToolTip = dataRow["Description"].ToString();
            }
        }
    }
 
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