Monday, March 12, 2012

How to convert from UserId to UserName in GridView?

i am using membership, and my GridView are using by choosing ObjectDataSource , In my ObjectDataSource i am using UserId, but when show the GridView i want the UserId changer UserName.How to do it? For example my some code,

<asp:TemplateField HeaderText="UserId"><ItemTemplate><%#Eval("UserId")%></ItemTemplate></asp:TemplateField>

You could write method that calls

MembershipUser u =Membership.GetUser(userID);.

username = u.UserName

Then call it from the template with <%# (String) MyGetUserNameMethod(String userid) %>

(declare the function protected string MyGetUseNameMethod in your code behind class)


Dear Sir,

Sorry i still can not understand!


hi

try this

<asp:TemplateField> <ItemTemplate><%#Membership.GetUser(Eval("UserId")).UserName%> </ItemTemplate> </asp:TemplateField>

Dear Sir,

Still can not!


hi

just replace your code with the one i gave you

so delete your templateField column and put my code

man if you still dont understand ,

could you explain what is the things that makes you confused

thanks


Dear Sir,

Thank!!it working,Sorry Sir, maybe just now i am typing wrong, Now, i am no error, Finally Thank you Sir!!!

Labels: , , , , , , , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home