Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have an SPGridview and I made a CAML Query to get the modifier of a document. When I bind it to the SPGridview with a SPBoundfield the value is displayed like this:

1;#HANSEVIS13\sschindler

All I want is that this field should be like a Sharepoint Standard SPFieldUser. How would I achieve this?

share|improve this question
    
I believe this may be very closely related: sharepoint.stackexchange.com/questions/17920/… –  Stuart Pegg Aug 17 '11 at 22:19
    
Circular reference? :) –  Rob D'Oria Aug 17 '11 at 23:17
    
@Stuart: So "closely related" = the same? haha :) –  Kit Menke Aug 18 '11 at 2:33
    
@Kit: Haha! Oops! sharepoint.stackexchange.com/q/7375/1529 Is the one I was thinking of. –  Stuart Pegg Aug 18 '11 at 7:20
    
@Rob: I did actually click that a couple times, thinking "Huh?" before I realised... –  Stuart Pegg Aug 18 '11 at 7:21
add comment

1 Answer 1

up vote 1 down vote accepted

Thanks for the comments. I didn't ry them but they seem very helpful.

I solved it with an Templatefield too but created a class and used a Linkbutton. Here's the code:

   public class TemplatedUserControl : ITemplate
   {
    private string loginName;
    private string displayName;

    public TemplatedUserControl(string loginName, string displayName)
    {
        this.loginName = loginName;
        this.displayName = displayName;
    }

    public void InstantiateIn(Control container)
    {
        LinkButton referUser = new LinkButton();
        referUser.DataBinding += new EventHandler(referUser_DataBinding);
        container.Controls.Add(referUser);
    }

    private void referUser_DataBinding(object sender, EventArgs e)
    {
        LinkButton referUser = (LinkButton)sender;
        GridViewRow container = (GridViewRow)referUser.NamingContainer;
        SPUser user = SPContext.Current.Web.AllUsers[userloginName]
        // Do something with the user
    }
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.