I am building my WebPart locally and when ready will deploy to SPO. I want to traverse the items of a list using LINQ (or whatever is most proper) and generate HTML based on those items.
That's all I want to do. That's all. I don't want to bind to a gridview or any other asp:control which I have no control on what it spits out and seems like an overkill to create my own (if that's even doable)
Why is this so hard to do ?
EDIT
Adding some more information to the question.
I have a list of projects (stored as list items with some properties and attachments) that need to be displayed through some custom HTML in the public facing site.
To be able to do this on my local environment I'm trying to build a simple web-part (based on this example http://msdn.microsoft.com/en-us/office365trainingcourse_lab_2_1_topic3 ) that does not need the button click.
It would obviously need the SPQuery code from that example (after some more research it seems that using LINQ on List Items is not as efficient as using SPQuery)
Here's what I have so far:
namespace ProjectsWebPart.ProjectsWebPart{
[ToolboxItemAttribute(false)]
public partial class ProjectsWebPart : WebPart{
public ProjectsWebPart(){
}
protected override void OnInit(EventArgs e){
base.OnInit(e);
InitializeControl();
}
protected void Page_Load(object sender, EventArgs e){
}
protected override void Render(System.Web.UI.HtmlTextWriter writer){
SPList sourceList = SPContext.Current.Web.Lists.TryGetList("Projects List");
SPQuery qry = new SPQuery();
qry.ViewFieldsOnly = true;
qry.ViewFields = "<FieldRef Name='Title' /><FieldRef Name='Author' />";
qry.RowLimit = 20;
String html = "";
foreach (SPListItem item in sourceList.GetItems(qry)){
html += "<span>" + item["Title"] + "</span>";
}
writer.WriteEncodedText(html);
base.Render(writer);
}
}
}
Obviously WriteEncodedText will do what it says so I'm not really generating HTML. The ascx file is just the configs up top, after I removed the 3 asp:controls
I come from the functional (Scala-Play based) world where simplicity is king. Chasing simplicity, I might be missing something obvious, so please let me know what that is. However if what I am saying makes sense, how do I now echo the HTML that I have built ?
A few more things that I would need is to pass parameters to the web-part. Is there a simple way of doing this ? I might need to filter by Project Title.
Thanks for any help on this.