LinQ Synthesis Exercises

Source: Internet
Author: User

Topic


National table:
N001 Han
N002 Manchu
N003 Tibetan

Score Table:
1S001 Sub001 95
2s001 Sub002 66
3s001 Sub003 75
4s002 Sub001 55
5S002 Sub002 58
6s002 Sub003 61
7S003 Sub001 87
8S003 Sub002 84
9s003 Sub003 61
10S004 Sub001 95
11s004 Sub002 91
12s004 Sub003 100

-------------------------------------------------------
1, using the table display, the display column name format is:

Student ID student name National birthday subject Score
S001 Zhang San Han 1995-5-5 Chinese 95
S001 Zhang San Han 1995-5-5 Mathematics 66
S001 Zhang San Han 1995-5-5 English 75
S002 John Doe Manchu 1996-6-6 Language 55
....
....

2, the combination of query function, query types are:
Fuzzy Student Name Search
Fuzzy search of national names
Accurate birthday Year
Accurately check the subject name

3, paging function, each page shows 3 articles

Think, score condition check, optional condition is greater than and less than

<%@ Page language="C #"autoeventwireup="true"codefile="Default.aspx.cs"inherits="_default"%><! DOCTYPE html>"http://www.w3.org/1999/xhtml">"Server"> <meta http-equiv="Content-type"Content="text/html; Charset=utf-8"/> <title></title> <style type="Text/css">Table {background-Color:blue; Width: -%; Font-size:20px; Text-Align:center;        } #tr_head {color:white; }. tr_main {background-Color:white; }    </style>"Form1"runat="Server">Student Name:<asp:textbox id="TextBox1"runat="Server"></asp:textbox><br/>Nationality Name:<asp:textbox id="TextBox2"runat="Server"></asp:textbox><br/>Birthday Year:<asp:textbox id="TextBox3"runat="Server"></asp:textbox><br/>Account Name:<asp:textbox id="TextBox4"runat="Server"></asp:textbox><br/> <asp:button id="Button1"runat="Server"text="Enquiry"/><br/> <asp:repeater id="Repeater1"runat="Server"> <HeaderTemplate> <table> <tr id="Tr_head"> <td> Student number </td> <td> student name </td>                        <td> nationalities </td> <td> birthdays </td> <td> subjects </td>            <td> Results </td> </tr> </HeaderTemplate> <ItemTemplate> &LT;TRclass="Tr_main"> <td><% #Eval ("Sscode")%></td> <td><% #Eval ("sname")%></td> <td><% #Eval ("snation")%></td> <td><% #Eval ("Sbirthday","{0:yyyy mm month DD Day}")%></td> <td><% #Eval ("Subjiectname")%></td> <td><% #Eval ("score")%></td> </tr> </ItemTemplate> <footertemplate></table ></FooterTemplate> </asp:Repeater>Current section "<asp:label id="Label1"runat="Server"text="1"></asp:Label>"page,<asp:linkbutton id="LB_PRV"runat="Server"> Prev </asp:LinkButton> <asp:linkbutton id="Lb_next"runat="Server"> Next </asp:LinkButton> </form></body>
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls; Public Partial class_default:system.web.ui.page{//It is difficult to keep the consistency of dataStudentdatadatacontext conn =NewStudentdatadatacontext (); intCount =3; List<Linq_Score> lls =NewList<linq_score>(); protected voidPage_Load (Objectsender, EventArgs e) {Button1.Click+ = button1_click;//EnquiryLb_prv. Click + = Lb_prv_click;//Previous PageLb_next. Click + = Lb_next_click;//Next Page//when the page first loads        if(!IsPostBack) {Lb_prv. Enabled=false;//previous page not availableLb_next. Enabled =true;//next page is not availableLLS =Selectsome (); varLLS1 = lls. Skip ((Convert.ToInt32 (Label1.Text)-1) * count). Take (count);//Show DataRepeater1.datasource =LLS1;        Repeater1.databind (); }    }    //Next Page    voidLb_next_click (Objectsender, EventArgs e) {Label1.Text= (Convert.ToInt32 (label1.text) +1). ToString ();//Current PageLLS = Selectsome ();//Check the data again every time you click        Doublenum = math.ceiling (lls. Count/(Count *1.0));//Max pages        varLLS1 = lls. Skip ((Convert.ToInt32 (Label1.Text)-1) * count). Take (count);//repeater data that needs to be bound        if(Label1.Text = =Num. ToString ()) {Lb_next. Enabled=false;//if the current page becomes the maximum number of pages, the Next button is unavailable} LB_PRV. Enabled=true;//just click on the next Page button and the previous button will be availableRepeater1.datasource = LLS1;//data pointRepeater1.databind ();//Data Binding    }    //Previous Page    voidLb_prv_click (Objectsender, EventArgs e) {Label1.Text= (Convert.ToInt32 (label1.text)-1). ToString ();//Current PageLLS = Selectsome ();//Check the data again every time you click        varLLS1 = lls. Skip ((Convert.ToInt32 (Label1.Text)-1) * count). Take (count);//data that needs to be bound        if(Label1.Text = ="1") {Lb_prv. Enabled=false;//the current page becomes 1, the previous button is unavailable} lb_next. Enabled=true;//just click on the previous page Annie, the next page button will be availableRepeater1.datasource = LLS1;//data pointRepeater1.databind ();//Data Binding    }    //Query button    voidButton1_Click (Objectsender, EventArgs e) {Label1.Text="1";//as soon as you click the Query button, the current page becomes 1Lb_prv. Enabled =false;//previous page becomes unavailableLb_next. Enabled =true;//next page becomes availableLLS = Selectsome ();//Querying Data        intnum = lls. Count;//number of bars to query data        varLLS1 = lls. Skip ((Convert.ToInt32 (Label1.Text)-1) * count). Take (count);//the displayed data        if(Num <= count)//The number of bars queried is less than or equal to the number of bars to display, and the previous Next button is not available{Lb_prv. Enabled=false; Lb_next. Enabled=false; } Repeater1.datasource=LLS1;    Repeater1.databind (); }    //querying data methods, returning a collection     PublicList<linq_score>Selectsome () {List<Linq_Score> list =NewList<linq_score>(); varLIST1 = conn. Linq_score.asqueryable ();//query all the data in the Linq_score table, do not execute, first put in this        varList2 =Conn.        Linq_score.asqueryable (); varList3 =Conn.        Linq_score.asqueryable (); varList4 =Conn.        Linq_score.asqueryable (); if(TextBox1.Text.Length >0)//If the textbox1 is not empty{List1= Conn. Linq_score.where (R =r.linq_student.student_name.contains (TextBox1.Text)); }        if(TextBox2.Text.Length >0)//If the textbox2 is not empty{List2= Conn. Linq_score.where (R =r.linq_student.linq_nation.nation_name.contains (TextBox2.Text)); }        if(TextBox3.Text.Length >0)//If the TextBox3 is not empty{list3= Conn. Linq_score.where (r = r.linq_student.student_birthday.value.year = =Convert.ToInt32 (TextBox3.Text)); }        if(TextBox4.Text.Length >0)//If the textbox4 is not empty{list4= Conn. Linq_score.where (r = R.linq_subject.subject_name = =textbox4.text); } list= List1. Intersect (List2). Intersect (LIST3). Intersect (LIST4). ToList ();//find the intersection of four sets        returnlist; }}

LinQ Synthesis Exercises

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.