protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { SetSitemap(); try { using (DataClassesDataContext data = new DataClassesDataContext()) { int ItemCount = int.Parse(data.GetPicturesItemCount().ToList()[0].ItemCount); AspNetPager1.RecordCount = ItemCount; GetPictures(); } } catch (Exception ex) { // error message here } } }