0

I'm trying to bind the last items of my list this is my code

          SPList myList = myWeb.Lists.TryGetList("Calendar List");

          SPListItemCollection items = myList.Items;

          EventCal.DataSource = items;
          EventCal.DataBind();

I tried this but it said that I'm missing a directive.

           EventCal.DataSource = items.Reverse();

this is my condition..

       protected void EventCal_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {



         if (e.Item.ItemIndex >= 3)
         {
             System.Web.UI.HtmlControls.HtmlGenericControl div = e.Item.FindControl("listItem") as System.Web.UI.HtmlControls.HtmlGenericControl;
            div.Visible = false;


         }



    }

and thanks in advance for your help..

1 Answer 1

1

You can use CAML Query to fetch data in descending order of creation. And to achieve this you can sort ID column in descending order.

SPList myList = myWeb.Lists.TryGetList("Calendar List");
SPQuery spQuery = new SPQuery();
spQuery.Query = "<OrderBy><FieldRef Name='ID' Ascending='False'/></OrderBy>";
SPListItemCollection items = myList.GetItems(spQuery);

Once you achieve items in descending order you can go ahead and achieve what you need.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.