DateTime.Now请帮助 [英] DateTime.Now Help Please

查看:84
本文介绍了DateTime.Now请帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨大家好!



如何按日期从SpList显示最新和最旧的新闻

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();
                           //LabelShowContents.Text = news["Contents"].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;
           }

           }

推荐答案

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);
 
                     
                    SPListItemCollection items = list.GetItems();
                    items= items.OrderByDescending(e=>e.Date).ToList();
 
                    foreach (SPListItem news in items)
                        
                    {
                            TextBoxContents.Text = news["Contents"].ToString();
                           
                            LabelShowTitle.Text = news["Title"].ToString();
                            //LabelShowContents.Text = news["Contents"].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;
            }
 
            }


这篇关于DateTime.Now请帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆