Hi Guys,
Thanks for visiting my blog .
In my previous posts i explained how to get the list items count from SharePoint List Using Content editor and ecma script.
In this Post I would like to explain the same concept using ECMA Script and Visual Studio.
Step :1 Open Visual Studio (Run as Administrator). Create an Empty SharePoint Project.
Step :2 Select Visual Webpart from available templates and add to the Solution .
Step :3 Open ascx file in Webpart. and Add the below Script files in order to refer SP.js files to start
work with ECMA Script .
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
Step :4 I want to display the list items count only when the button clicked not by default page gets
loaded .
<input type="button" id="btnSubmit" value="Get The Item Count">.
Step 5 : Add the Script file .
<script type="text/javascript">
$(document).ready(function () {
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', MainFunction);
});
var objContext = null;
var objWeb = null
var objList = null;
var objItem = null;
function MainFunction() {
objContext = new SP.ClientContext.get_current();
objWeb = objContext.get_web();
objList = objWeb.get_lists().getByTitle("SampleList"); // Passing the list name here.
objContext.load(objList);
objContext.executeQueryAsync(Function.createDelegate(this, this.onSuccess), Function.createDelegate(this, this.onFail));
}
function onSuccess(sender, args) {
ItemSubmit(); //calls the button Click event.
}
function onFail(sender, args) {
alert('Some error has occured.');
}
function ItemSubmit() {
$("#btnSubmit").click(function () {
alert('SharePoint Kitchen shows List items count : ' + objList.get_itemCount());
});
}
</script>
Please find the screen shot below of code .
Please deploy the solution and place the web part in one site page and test by clicking on the button .
Related Post
ECMA Script
- Get List Field Type using ECMA Script in SP Hosted Apps
- Get Choice Field Type Values using ECMA Script
- Executing Search Queries using ECMA Script in SharePoint 2013
- Create Site Column and Adding it to Content Type using ECMA Script
- Create Content Type using ECMA Script
- Get List Content Types using ECMA Script
- Get Lookup Column Value using ECMA Script
- Create Folder in document Library using ECMA Script in SharePoint Hosted Apps
- Delete List Item Collection using ECMA Script
- Get List Item attachments using ECMA Script
- How to get the List Items Count of SP List using ECMA Script in SharePoint 2010 ,2013
- SharePoint Client Object Model using ECMAScript in 2013
SharePoint 2010
- List view render using JSLink with Fabric UI
- Delete Quick Links using Powershell
- delete/Add Top Navigation Links using Powershell
- PowerShell::Get Content Database Size in SharePoint
- PowerShell :: Delete All List Items
- Basics: Difference between Synchronous Events and Asynchronous Events in SharePoint
- Remove-SPSite 0x80070003 - Forcely delete Site Collection that cannot be deleted
- This operation can be performed only on a computer that is joined to a server farm by users who have permissions in SQL Server to read from the configuration database. To connect this server to the server farm, use the SharePoint Products Configuration Wizard, located on the Start menu in Microsoft SharePoint 2010 Products.
- Restore-SPSite: The operation that you are attempting to perform cannot be completed successfully.
- Get List Field Type using ECMA Script in SP Hosted Apps
- SharePoint Interview Questions and Answers..
- What are Event Receivers and How to Create Sample event Receivers and attach to List/ Doc Library ?
- Export SharePoint Search Crawl log to CSV File.
- Create Content Type using ECMA Script
- Get List Content Types using ECMA Script
- SharePoint Modal Dailoge to Open Page
- SPDataSource in SharePoint.
- Capacity planning and Sizing in SharePoint 2010
- Enable 'Save site as Template' in Publishing Sites by using SharePoint Designer
- Read Enhanced Rich Text Values in SharePoint
- What is Web part life Cycle in SharePoint 2013 and SharePoint 2010
- How to Hide Controls in SharePoint New Form Based on User using ECMA Script.
- What is the Content Type for Custom List in SharePoint 2013, SharePoint 2010
- What is calculated column in SharePoint 2013 ,2010
- Create Meetings by using Exchange Server API
0 comments:
Post a Comment