Hi Guys!
How to display Latest and oldest news on site from SpList by date
try
{
using (SPSite site = new SPSite("http://wingtip:49074"))
{
LabelShowTitle.Text = string.Empty;
LabelShowContents.Text = string.Empty;
LabelShowDatum.Text = string.Empty;
LabelAuthor.Text = string.Empty;
LabelLink.Text = string.Empty;
SPWeb web = SPContext.Current.Web;
SPList list = web.Lists.TryGetList(DropDownListSelectCategory.SelectedItem.Value);
DateTime dt = DateTime.Now;
SPListItemCollection items = list.GetItems();
foreach (SPListItem news in items)
{
TextBoxContents.Text = news["Contents"].ToString();
LabelShowTitle.Text = news["Title"].ToString();
LabelShowDatum.Text = news["Date"].ToString();
LabelAuthor.Text = news["Authors"].ToString();
LabelLink.Text = new SPFieldUrlValue(news["Links"].ToString()).Url;
}
site.Dispose();
}
}
catch(Exception x)
{
LabelError.Text = x.Message;
}
}