Front Code:
<%@ page language= "C #" autoeventwireup= "true" codefile= "LINQ data Display. Aspx.cs" inherits= "LINQ data Display"%><! DOCTYPE html>CSS code:
* { margin:0px; padding:0px;} body { min-width:1000px;} #xuanze { position:relative; width:100%; height:50px; line-height:50px;} Table { width:100%; Text-align:center; Background-color:navy;} #head { color:white;}. Mian { background-color:white;} TD { padding:5px;}
Background code:
Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.UI;using System.web.ui.webcontrols;public partial class LINQ data display: system.web.ui.page{datadatacontext con = new Datadatacontext (); List<linq_score> score = new list<linq_score> (); int count = 3; protected void Page_Load (object sender, EventArgs e) {Button1.Click + = button1_click; Linkbutton1.click + = LinkButton1_Click; Linkbutton2.click + = Linkbutton2_click; if (! IsPostBack) {//Load birthday Fangfa (1900, DateTime.Now.Year, DropDownList2);//Year score = Co N.linq_score.tolist (); Repeater1.datasource = SEL (). Skip (0). Take (count); Repeater1.databind (); Label1.Text = "1"; linkbutton1.enabled = false; }}//Next page void Linkbutton2_click (object sender, EventArgs e) {score = sel (); int pagenum = Convert.ToInt32 (Label1.Text); pagenum++; Repeater1.datasource = SEL (). Skip ((pagenum-1) * count). Take (count); Repeater1.databind (); Label1.Text = Pagenum. ToString (); Linkbutton1.enabled = true; if (Pagenum = = max (score)) {linkbutton2.enabled = false; }}//previous page void LinkButton1_Click (object sender, EventArgs e) {score = sel (); int pagenum = Convert.ToInt32 (Label1.Text); pagenum--; Repeater1.datasource = SEL (). Skip ((pagenum-1) * count). Take (count); Repeater1.databind (); Label1.Text = Pagenum. ToString (); Linkbutton2.enabled = true; if (Label1.Text = = "1") {linkbutton1.enabled = false; }}//maximum number of pages public int max (list<linq_score> li) {return Convert.ToInt32 (math.ceiling (SEL). count/3.0)); }//Query button click event void Button1_Click (object sender, EventArgs e) {score = sel (); int pagenum = 1; Repeater1.datasource = SEL (). SkIP ((pagenum-1) * count). Take (count); Repeater1.databind (); if (max (score) = = 1) {linkbutton1.enabled = false; linkbutton2.enabled = false; } else {linkbutton1.enabled = false; Linkbutton2.enabled = true; }}///<summary>///Check out the collection///</summary>//<returns></returns> public List <Linq_Score> sel () {var list1 = con. Linq_score.asqueryable (); var list2 = con. Linq_score.asqueryable (); var list3 = con. Linq_score.asqueryable (); var list4 = con. Linq_score.asqueryable (); var list5 = con. Linq_score.asqueryable (); Name if (TextBox1.Text.Trim (). Length > 0) {list1 = List1. Where (r = r.linq_student.student_name = = TextBox1.Text.Trim ()); }//National if (DropDownList1.SelectedItem.Text! = "= Please select =") {List2 = List2. Where (r = R.linq_student.liNq_nation.nation_name = = DropDownList1.SelectedItem.Text); }//Birthday if (DropDownList2.SelectedItem.Text! = "= Please select =") {List3 = List3. Where (r = r.linq_student.student_birthday.value.year.tostring () = = DropDownList2.SelectedItem.Text); }//Account if (DropDownList3.SelectedItem.Text! = "= Please select =") {List4 = List4. Where (r = r.linq_subject.subject_name = = DropDownList3.SelectedItem.Text); }//Score if (DropDownList4.SelectedItem.Text! = "= Please select =") {if (DropDownList4.SelectedItem.Te XT = = "<") {List5 = List5. Where (r = R.score < Convert.todecimal (TextBox2.Text)); } else if (DropDownList4.SelectedItem.Text = = "=") {list5 = List5. Where (r = R.score = = Convert.todecimal (TextBox2.Text)); } else if (DropDownList4.SelectedItem.Text = = ">") {list5 = LisT5. Where (r = r.score > Convert.todecimal (textbox2.text)); } else if (DropDownList4.SelectedItem.Text = = "<=") {list5 = List5. Where (r = R.score <= convert.todecimal (TextBox2.Text)); } else if (DropDownList4.SelectedItem.Text = = ">=") {list5 = List5. Where (r = R.score >= convert.todecimal (TextBox2.Text)); }} return List1. Intersect (List2). Intersect (LIST3). Intersect (LIST4). Intersect (LIST5). ToList (); } public void Fangfa (int start, int end, DropDownList DDL) {for (int i = start; I <= end; i++) { ListItem li = new ListItem (); Li. Text = i.ToString (); Li. Value = i.ToString (); Ddl. Items.Add (LI); } }}
With the LINQ class
LINQ Advanced Search and Paging