Example of a parallel ranking in the GridView SQL Server Edition

Source: Internet
Author: User
Tags eval

SQL Server database version

<%@ Page language=" c#" Autoeventwireup="true"%> <script runat="server"> public int trapezoidindex = 1; int lastnumer = 0; protected void Page_Load (object sender, EventArgs e) {string ConnectionString = " Persist Security Info=false; User Id=sa; Password=;initial Catalog=book; Server=.; "; System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection (ConnectionString); cn. Open (); String sql = "select *, (Yuwen + Shuxue + Yingyu) as Totalscore from [Score] ORDER by Totalscore desc"; System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand (SQL, CN); System.Data.SqlClient.SqlDataReader dr = cmd. ExecuteReader (System.Data.CommandBehavior.CloseConnection); Gridview1.datasource = Dr; Gridview1.databind (); Dr. Close (); Cmd. Dispose (); cn. Dispose (); } protected void Gridview1_rowcreated (object sender, GridViewRowEventArgs e) {if (E.row.rowtype = = Datacontrolrowtype.datarow) {System.Data.Common.DbDataRecord db = (System.Data.Common.DbDataRecord) e. Row.dataitem; int totalscore = Int32.Parse (db[" Totalscore"]. ToString ()); if (E.row.rowindex = = 0) {Lastnumer = Totalscore;} if (Lastnumer!= totalscore) {trapezoidindex = E.row.rowindex + 1;} Lastnumer = Totalscore; }} </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head id=" head1" Runat="server"> <title> Example of the GridView parallel rankings </title> </head> <body> <form id="form1" Runat="server"> <asp:gridview id=" gridview1" runat="server" autogeneratecolumns="false" onrowcreated=" gridview1_rowcreated" Width="600px"> < Columns> <asp:templatefield Headertext=" Data Serial number "> <ItemTemplate> <% #Container. Dataitemindex + 1%> </ItemTemplate> </asp:TemplateField> <asp:templatefield headertext=" Student Name "> <ItemTemplate> <% #Eval (" username")%> </ItemTemplate> </asp:TemplateField> <asp:templatefield headertext=" Language "> <ItemTemplate> <% #Eval (" yuwen")%> </ItemTemplate> </asp:TemplateField> <asp:templatefield headertext=" Mathematics "> <ItemTemplate> <% #Eval (" shuxue")%> </ItemTemplate> </asp:TemplateField> <asp:templatefield headertext=" English "> <ItemTemplate> <% #Eval (" yingyu")%> </itemtemplate> </asp:TemplateField> <asp:templatefield headertext=" Total Score "> <itemstyle font-bold="true" forecolor="red" /> <ItemTemplate> <% #Eval (" totalscore")%> </ItemTemplate> </asp:TemplateField> <asp:templatefield headertext=" Rankings "> <ItemTemplate> <% #TrapezoidIndex%> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </form> </body> </html>

Related Article

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.