GridView中实现并列排名的例子[access版]

<%@ 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>

时间: 2024-07-28 16:54:13

GridView中实现并列排名的例子[access版]的相关文章

GridView中实现并列排名的例子 SQL Server版

SQL Server数据库版本 <%@ Page Language="C#" AutoEventWireup="true"%> <script runat="server"> public int TrapezoidIndex = 1; int LastNumer = 0; protected void Page_Load( object sender, EventArgs e ) { string ConnectionS

asp.net中获取新增加记录的ID Access版_实用技巧

这里参考了Erist.Protal里的代码 复制代码 代码如下: /// <summary> /// 增加新的文章 /// </summary> /// <param name="ArticleTitle"></param> /// <param name="Author"></param> /// <param name="ArticleFrom"></p

ASP.NET2.0中Gridview中数据操作技巧

asp.net|技巧|数据     Asp.net 2.0中新增的gridview控件,是十分强大的数据展示控件,在前面的系列文章里,分别展示了其中很多的基本用法和技巧(详见<<ASP.NET 2.0中Gridview控件高级技巧>>.<<ASP.NET2.0利用Gridview实现主从关系>>).在本文中,将继续探讨有关的技巧. 一.Gridview中的内容导出到Excel 在日常工作中,经常要将gridview中的内容导出到excel报表中去,在asp.

提高在google中排名的重点(精简版)

中介交易 SEO诊断 淘宝客 云主机 技术大厅 网站优化和提高在google中排名的重点 (精简版)    Google的排名运算法则主要使用了两个部分,第一个部分是它的文字内容匹配系统.Google使用该系统来发现与搜索者键入的搜索词相关的网页:第二部分也是排名运算法则中最最重要的部分,就是Google的专利网页级别技术.  (title)中出现的关键字给予较高的权值,所以你应当确保在你网站的标题标签中包含了最重要的关键词,即应围绕你最重要的关键词来决定网页标题的内容.不过网页的标题不可过长,

代码-Android中GridView中当我删除某一个图片时图片缓存清空,图片位置上显示背景图

问题描述 Android中GridView中当我删除某一个图片时图片缓存清空,图片位置上显示背景图 请问如何实现我是新手,最好有个详细的代码给我做个参考谢谢大家 解决方案 把数据源中的图像连接去掉,然后notify,getview中判断,如果图像连接没有,就显示默认图片 解决方案二: 那么怎么清除数据源那,我是个新手对代码还不是很熟 解决方案三: 删除后,手动把背景图设置上去-- 解决方案四: 谁能写个代码例子给我参考一下,只是告诉我方式我不知道改怎么做.谢谢大家了 解决方案五: 你重新吧背景图

Gridview中如何对IP地址列排序

问题描述 IP地址以字符型存储,直接使用Gridview中的排序功能会得到错误结果.如10.12.3.8会排在10.2.3.5的前面. 解决方案 解决方案二:哪在sql里面写吧!解决方案三:通过SQLSERVER存储过程实现IP地址排序网上有例子,也实验成功了.但是直接用到Gridview中还是不会.解决方案四:你的数据已经查好了,直接绑定不行吗?解决方案五:但是还有别的条件要排序的,不是在Gridview中只有一种排序方式.我是想在需要的时候点击IP地址列实现IP地址的排序,也可以按需要点击别

GridView中日期不显示时分秒的完美解决方法_实用技巧

两种处理方式: 1.模版列:假设数据表的字段completeTime的类型为时间格式 <asp:TemplateField HeaderText="时间"> <ItemTemplate> <%#Eval("completeTime", "{0:yyyy-MM-dd}")%> </ItemTemplate> </asp:TemplateField> 2.绑定列: <asp:Bound

把存入数据库中的图片取出来,显示在GridView中是没有问题的,但是要用marquee来滚动显示从数据库中读出的图片怎么办?

问题描述 谢谢!如果不能回答上面的问题,给我一个menu邦定数据库的例子我给分的!VS2005 解决方案 解决方案二:<marquee><imgsrc="image.aspx?id=111"></marquee>在image.aspx里面显示图片的程序解决方案三:Response.Clear();Response.ContentType="image/jpeg";Response.BinaryWrite(b);显示图片的最简单的几

gridview中的checkbox选择

问题描述 protectedvoidCheckBox1_CheckedChanged(objectsender,EventArgse){for(inti=0;i<=dv.Rows.Count-1;i++){CheckBoxchk=(CheckBox)dv.Rows[i].FindControl("ck");if(CheckBox1.Checked==true){chk.Checked=true;//TextBox1.Text="112";}elsechk.Ch