Skip to content

Instantly share code, notes, and snippets.

@emiliano-poggi
Created February 5, 2012 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emiliano-poggi/1744459 to your computer and use it in GitHub Desktop.
Save emiliano-poggi/1744459 to your computer and use it in GitHub Desktop.
Javascript to display sharepoint list items on page load
<asp:Content ContentPlaceholderID="PlaceHolderMain" runat="server">
<script type="text/javascript">
window.onload = function() {
ExecuteOrDelayUntilScriptLoaded(ViewItem, "sp.js");
}
</script>
<div id="test">
</div>
</asp:Content>
<asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server">
<SharePointWebControls:ScriptLink Name="SP.js" runat="server" OnDemand="true" Localizable="False" />
<script src="/cs/Style Library/CustomStyles/scripts/jquery.tools.min.js" type="text/javascript"></script>
<script type="text/javascript">
function ViewItem()
{
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var list = web.get_lists().getByTitle('Service Basket');
var query = SP.CamlQuery.createAllItemsQuery();
allItems = list.getItems(query);
context.load(allItems, 'Include(Title)');
context.executeQueryAsync(Function.createDelegate(this, this.success), Function.createDelegate(this, this.failed));
}
function success() {
var TextFiled = "";
var ListEnumerator = this.allItems.getEnumerator();
$('#test').append('<ul>');
while(ListEnumerator.moveNext())
{
var currentItem = ListEnumerator.get_current();
$('#test').append('<li>'+currentItem.get_item('Title') + '</li>\n');
}
$('#test').append('</ul>');
}
function failed(sender, args) {
alert("failed. Message:" + args.get_message());
}
</script>
</asp:Content>
<asp:Content ContentPlaceholderID="PlaceHolderMain" runat="server">
<script type="text/javascript">
$(document).ready(function(){
ExecuteOrDelayUntilScriptLoaded(ViewItem, "sp.js");
})
</script>
<div id="test">
</div>
</asp:Content>
<asp:Content ContentPlaceholderID="PlaceHolderMain" runat="server">
<script type="text/javascript">
$(function(){
ExecuteOrDelayUntilScriptLoaded(ViewItem, "sp.js");
})
</script>
<div id="test">
</div>
</asp:Content>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment