%@ Import Namespace="System"> <%@ Import Namespace="System" />
扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
Access数据库版本
<!--StartFragment--><%@ Page Language="C#" AutoEventWireup="true" Debug="true" %> <%@ Import Namespace="System.Data" %> <script runat="server"> public int TrapezoidIndex = 1; int LastNumer = 0; protected void Page_Load( object sender, EventArgs e ) { //ASPNET20Book.mdb数据库参见《ASP.NET 2.0应用开发技术》一书的光盘 string ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\ASPNET20Book.mdb;Persist Security Info=True"; System.Data.OleDb.OleDbConnection cn = new System.Data.OleDb.OleDbConnection(ConnectionString); cn.Open(); string sql = "select * from [Score] Order BY Shuxue DESC"; System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand(sql, cn); System.Data.OleDb.OleDbDataReader dr = cmd.ExecuteReader(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 Shuxue = Int32.Parse(db["Shuxue"].ToString()); if (e.Row.RowIndex == 0) { LastNumer = Shuxue; } if (LastNumer != Shuxue) { TrapezoidIndex = e.Row.RowIndex + 1; } LastNumer = Shuxue; } } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>GridView并列排名的例子</title> </head> <body> <form id="form1" runat="server"> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowCreated="GridView1_RowCreated"> <Columns> <asp:TemplateField HeaderText="数据序号"> <ItemTemplate> <%#Container.DataItemIndex + 1%> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="学生姓名"> <ItemTemplate> <%#Eval("UserName")%> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="数学"> <ItemTemplate> <%#Eval("Shuxue")%> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="排名"> <ItemTemplate> <%#TrapezoidIndex%> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </form> </body> </html> |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者