Friday, 8 June 2012

Add Presence Icon to SPGridview

I spent hours trying to figure out why my presence image only appears for the last instance of the particular user, and I finally figured out why, id has to be unique.
to show image presence, I attached to rowdatabound event with the required javascript

       protected void gvProjOverview_RowDataBound(object sender, GridViewRowEventArgs e)
        { 
            if(e.Row.DataItem!=null)
            {
                SPWeb web = SPContext.Current.Web; 

                SPUser user = web.EnsureUser("DOMAIN\login");
 
                e.Row.Cells[4].Text = ""
                    + " "
                    + ""
                    + "" + user.Name +  ""
                    + "";
            }
        }

id='imn_" + e.Row.RowIndex <- this was where I had used user.ID which was not unique and thus the presence icon was only showing for one of the available users.

The lack of distinct ID causes some presence icon to disappear, that is, if user Andy is on two of the rows, the presence icon only appears for the last row where Andy is in.

No comments:

Post a Comment