I am trying to develop a custom visual web part to display the latest 5 announcements with the images that are attached from the OOTB announcement lsit.I have a repeater control with an Item Template to render sharepoint list items. I am trying to understand the right process and syntax to bind data to my item template controls. Here is my ascx page:
And here is the code behind:
SPWeb web = SPContext.Current.Web;
SPList list = web.Lists["Announcements"];
SPQuery spQuery = new SPQuery();
spQuery.Query = " <Where><IsNotNull><FieldRef Name='Title' /></IsNotNull></Where> <OrderBy> <FieldRef Name='ID' Ascending='False' /> </OrderBy> ";
spQuery.RowLimit = 5;
SPListItemCollection oListCollection = list.GetItems(spQuery);
repeatMyAnnouncements.ItemDataBound += new RepeaterItemEventHandler(repeatMyAnnouncements_ItemDataBound);
repeatMyAnnouncements.DataSource = oListCollection;
repeatMyAnnouncements.DataBind();
}
//My understanding beyond this is severly limited and I just cant seem to wrap my head around how to add my Announcement List Title(as a link to edit) and the images.
private void repeatMyAnnouncements_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
HyperLink hypImageEditLink = (HyperLink)e.Item.FindControl("hypImageEditLink");
HyperLink hypTextEditLink = (HyperLink)e.Item.FindControl("hypTextEditLink");
SPListItem item = (SPListItem)e.Item.DataItem;
string url = (string) item["Url"];
hypImageEditLink.NavigateUrl = data;
hypTextEditLink.NavigateUrl = data;
hypTextEditLink.Text = "Link";
//TODO: set image url
string imageUrl= item.Attachments.UrlPrefix;
}
if there are some good links that can help me get a basic understanding of the process and syntax please do mention as well. Thanks
@Brian: Here is the ascx code I have: