Print out HTML from aspx.cs to aspx page
-
2012年6月28日 0:25
I am trying to print out the following announcement Titles on my aspx web page that i retrieved from a sharepoint site that i put in the aspx.cs file. How do i go about printing this information out directly on the aspx page from the aspx.cs file?
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.SharePoint.Client;
using SP = Microsoft.SharePoint.Client;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string siteUrl = "http://win-l1l6hbqrvsh";
ClientContext clientContext = new ClientContext(siteUrl);
Web site = clientContext.Web;
clientContext.Load(site);
clientContext.ExecuteQuery();
SP.List oList = clientContext.Web.Lists.GetByTitle("Announcements");
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "<View><Query><OrderBy><FieldRef Name='Title' /></OrderBy></Query></View>";
ListItemCollection collListItem = oList.GetItems(camlQuery);
clientContext.Load(collListItem);
clientContext.ExecuteQuery();
foreach (ListItem oListItem in collListItem)
{
Response.Write("<li> Title: " + oListItem["Title"] + "</li>");
}
}
}
全部回复
-
2012年6月30日 14:29
Hi,
There's several ways to output your results to the page.
One way is to modify the ASPX page and add a <asp:Panel> or other control, then populate it's Controls-collection with the data.
Anotherone is to simply do something like this:
foreach (ListItem oListItem in collListItem) { Controls.Add(new Literal { Text ="<li> Title: " + oListItem["Title"] + "</li>" }); }
Tobias Zimmergren
Microsoft MCP, MCTS, MCT, MVP (SharePoint)
Blog: www.zimmergren.net
Twitter: twitter.com/zimmergren
Corporate site: www.tozit.com- 已建议为答案 Bjoern H RappMicrosoft Community Contributor, Moderator 2012年6月30日 16:23
- 已标记为答案 Qiao WeiMicrosoft Contingent Staff, Moderator 2012年7月5日 10:26

