[导入]GridView中实现并列排名的例子
2007-11-14 16:22
323 查看
Access数据库版本 <%@ Page Language="C#" AutoEventWireup="true" Debug="true" %> <%@ Import Namespace="System.Data" %> 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; } } GridView并列排名的例子 <%#Container.DataItemIndex + 1%> <%#Eval("UserName")%> <%#Eval("Shuxue")%> <%#TrapezoidIndex%> SQL Server数据库版本 <%@ Page Language="C#" AutoEventWireup="true"%> 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; } } GridView并列排名的例子 <%#Container.DataItemIndex + 1%> <%#Eval("UserName")%> <%#Eval("Yuwen")%> <%#Eval("Shuxue")%> <%#Eval("Yingyu")%> <%#Eval("TotalScore")%> <%#TrapezoidIndex%>
文章来源:http://dotnet.aspx.cc/article/7e82096a-b4f7-4012-b873-e1d51705e166/read.aspx
相关文章推荐
- [导入]GridView中实现并列排名的例子
- GridView中实现并列排名的例子
- 一个Excel导入SQL server的例子(分别使用游标、CTE、master..spt_values实现)
- 一个在ASP.NET中利用服务器控件GridView实现数据增删改查的例子
- [导入]GridView 实现服务器端和客户端全选的两种方法
- MYSQL实现排名及查询指定用户排名功能(并列排名功能)实例代码
- 一个Excel导入SQL server的例子(分别使用游标、CTE、master..spt_values实现)
- 将GridView导入到Excel和word(完全可实现)
- [导入]ASP.NET 2.0中GridView无限层复杂表头的实现
- [导入][原创]一个通过BackgroundWorker实现WinForm异步操作的例子
- [导入]GridView 实现服务器端和客户端全选的两种方法
- 将GridView导入到Excel和word(完全可实现)
- [导入]Asp.net 2.0 自定义控件开发[实现GridView多行表头固定表体滚动效果][示例代码下载]
- [导入]ASP.NET 2.0中GridView无限层复杂表头的实现
- 一个Excel导入SQL server的例子(分别使用游标、CTE、master..spt_values实现)
- [导入]利用GridView显示主细表并一次编辑明细表所有数据的例子【回网友帖子】
- asp.net中实现GridView中的数据导入到Excel中
- [导入]ASP.NET 2.0 中动态添加 GridView 模板列的例子
- [导入]一个 NHIBERNATE+GRIDVIEW 添加删除修改的例子(单表)
- [导入]用Table实现GridView控件功能