none
In Sharepoint office 365BIND THE USERS NAMES INTO DROPDOWN AND WHEN THE ADMIN SELECT THE NAME OF USER DISPLAY THE PROFILE IMAGE AND NAME RRS feed

  • Question

  • Hi All,

    Please help me to bind the users name to dropdown and when user select the perticular name of user the profile Image of user and name should be displayed in webpart of sharepoint office 365.

    Thanks,

    pavan.


    • Edited by pavanguntha Tuesday, March 7, 2017 12:53 PM
    Tuesday, March 7, 2017 12:52 PM

All replies

  • Hi Pavan,

    We can get site users using REST API with jQuery Ajax, the following code for your reference. Add the code into Script Editor web part into the web part page.

    <script src="//code.jquery.com/jquery-3.1.0.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(function () { 
    	var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/siteusers?$select=Id,Title,Email";
    	$.ajax({
    		url: url,
    		method: "GET",
    		async: false,
    		headers: { "Accept": "application/json; odata=verbose" },
    		success: function (data) {
    			var items=data.d.results;
    			var options="<option value=''>--select a user--</option>";
    			for(var i=0;i<items.length;i++){
    				if(items[i].Email!=""){
    					options+="<option value='"+items[i].Email+"'>"+items[i].Title+"</option>";
    				}
    			}
    			$("#SiteUsers").html(options);
    		},
    		error: function (data) {
    		}
    	});
    	$("#SiteUsers").change(function(){
    		var html="";
    		if($(this).val()!=null&&$(this).val()!=""){
    			html+="<img src='/_layouts/15/userphoto.aspx?size=L&username=" + $(this).val() + "'/>";
    			if($(this).children(':selected').text()!=""){
    				html+="<p><span>Name:"+ $(this).children(':selected').text()+"</span></p>";		
    			} 
    		}				 
    		$("#UserInfomation").html(html);
    	});
    });
    </script>
    
    <select id="SiteUsers"><option>--select a user--</option></select>
    <div id="UserInfomation">
    </div>

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Wednesday, March 8, 2017 8:22 AM
    Moderator