protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { var quests = new List <QuestionModel>(); var stext = searchText.Text; stext = "%" + stext.ToLower() + "%"; if (string.IsNullOrEmpty(stext)) { var selectedQtype = long.Parse(DropDownList1.SelectedValue); quests = _db.ActiveQuestions_vw.AsEnumerable().Where(x => x.TypeId == selectedQtype && x.TenantId == long.Parse(SessionHelper.GetTenantID(Session))).Select(a => new QuestionModel { ID = a.Id, Detail = a.Details, Type = a.Type, Preamble = a.Preamble, Section = a.Section.ToString(), OptionType = a.OptionType, OptionsCount = a.OptionsCount.ToString(), IsActive = a.IsActive, // D = "<a id='" + a.Id.ToString() + "' onclick='deleteQuest(this)' href='#' >Delete</a>" D = a.D }).Distinct().ToList(); } else { quests = _db.SearchActiveQuestion(stext).OrderBy(x => x.Section).Select(a => new QuestionModel { ID = a.Id, Detail = a.Details, Type = a.Type, Preamble = a.Preamble, Section = a.Section, OptionType = a.OptionType, OptionsCount = a.OptionsCount.ToString(), IsActive = a.IsActive, // D = "<a id='" + a.Id.ToString() + "' onclick='deleteQuest(this)' href='#' >Delete</a>" D = a.D }).Distinct().ToList(); } GridView1.DataSource = quests; QuestionIndex.Text = quests.Count + " Question(s)"; GridView1.PageIndex = e.NewPageIndex; GridView1.DataBind(); }