Download Code
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="testPage.aspx.cs" Inherits="SharePoint2010.WCF.Examples.Layouts.SharePoint2010.WCF.Examples.testPage" DynamicMasterPageFile="~masterurl/default.master" %>
<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
<script type="text/javascript" src="/_layouts/js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function () {
//use the getJSON mehtod of Jquery
$.getJSON("http://ilinksys-106:8055/_vti_bin/listdata.svc/EmployeeList?$orderby=Modified%20desc", function (data) {
var strTitle = "";
//prepare HTML to render output to DIV resultarea
var html = "";
html = html + '<table width="100%" border="1"><tbody>';
html += '<tr><td><h3>Employee Name</h3></td><td><h3>Title</h3></td><td><h3>Employee Number</h3></td></tr>';
//iterate through all returned list items
$.each(data.d.results, function (i, result) {
//get item property
html += '<tr><td>' + result.EmployeeName + '</td><td>' + result.Title + '</td><td>' + result.EmployeeNumber + '</td></tr>';
});
//finally close table and render HTML to DIV resultarea
html = html + '</tbody></table>';
$('#resultarea').append($(html));
});
function createListItem(webUrl, listName, itemProperties, success, failure) {
$.ajax({
url: webUrl + "/_vti_bin/listdata.svc/" + listName,
type: "POST",
processData: false,
contentType: "application/json;odata=verbose",
data: JSON.stringify(itemProperties),
headers: {
"Accept": "application/json;odata=verbose"
},
success: function (data) {
success(data.d);
},
error: function (data) {
failure(data.responseJSON.error);
}
});
}
$("button:#Get").click(function () {
var taskProperties = {
'Title': $('#txtTitle').val(),
'EmployeeName': $('#txtEmpName').val(),
'EmployeeNumber': $('#txtEmpNumber').val()
};
createListItem('http://ilinksys-106:8055', 'EmployeeList', taskProperties, function (task) {
alert('Item' + task.EmployeeName + ' has been created');
},
function (error) {
console.log(JSON.stringify(error));
}
);
});
});
</script>
</asp:Content>
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<table width="500px">
<tr>
<td>Employee Title</td>
<td>
<input id="txtTitle" type="text" /></td>
</tr>
<tr>
<td>Employee Name</td>
<td>
<input id="txtEmpName" type="text" /></td>
</tr>
<tr>
<td>Employee Number</td>
<td>
<input id="txtEmpNumber" type="text" /></td>
</tr>
<tr>
<td> </td>
<td>
<button id="Get">Insert</button></td>
</tr>
<tr>
<td colspan="2">
<div id="resultarea"></div>
</td>
</tr>
</table>
</asp:Content>
<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
Application Page
</asp:Content>
<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server">
My Application Page
</asp:Content>
No comments:
Post a Comment