上下主题
protected void Page_Load(object sender, EventArgs e) { int.TryParse(Request["ID"], out queryID); if (!IsPostBack) { BindData(queryID); } } public void BindData(int ID) { var result = from f in siteData.共青团_团建活动 where f.Id == ID orderby f.创建时间 descending select new { ID=f.Id, 创建时间=f.创建时间, 标题=f.标题, 正文=f.正文 }; fv_PartyActivity.DataSource = result; fv_PartyActivity.DataBind(); ViewState["ID"] = ID; ViewState["Title"] = result.FirstOrDefault().标题; } protected void PrePage_Click(object sender, EventArgs e) { var result = siteData.共青团_团建活动.OrderByDescending(item => item.创建时间).ToList(); int index = result.FindIndex(item => item.Id== Convert.ToInt32(ViewState["ID"])); if (index > 0) { index--; if (result.ElementAt(index).Id.HasValue) { int ID = result.ElementAt(index).Id.Value; BindData(ID); } } } protected void NextPage_Click(object sender, EventArgs e) { var result = siteData.共青团_团建活动.OrderByDescending(item => item.创建时间).ToList(); int index = result.FindIndex(item => item.Id == Convert.ToInt32(ViewState["ID"])); if (index < result.Count() - 1) { index++; if (result.ElementAt(index).Id.HasValue) { int ID = result.ElementAt(index).Id.Value; BindData(ID); } } }