DataGrid 完全攻略之四 (实现统计)

前台代码:html
ExpandedBlockStart.gifContractedBlock.gif<%dot.gif@ Page language="c#" Codebehind="UserCount.aspx.cs" AutoEventWireup="false" Inherits="MsDataGrid.UserCount" %>
None.gif
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
None.gif
<HTML>
None.gif    
<HEAD>
None.gif        
<title>DataGrid使用举例</title>
None.gif        
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
None.gif        
<meta name="CODE_LANGUAGE" Content="C#">
None.gif        
<meta name="vs_defaultClientScript" content="JavaScript">
None.gif        
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
None.gif    
</HEAD>
None.gif    
<body MS_POSITIONING="GridLayout">
None.gif        
<form id="Form1" method="post" runat="server">
None.gif            
<FONT face="宋体">
None.gif                
<asp:DataGrid id="dgShow" style="Z-INDEX: 101; LEFT: 31px; POSITION: absolute; TOP: 93px" runat="server" Width="842px" Height="172px" BorderColor="Tan" BorderWidth="1px" BackColor="LightGoldenrodYellow" CellPadding="2" GridLines="None" ForeColor="Black" PageSize="1" AutoGenerateColumns="False" ShowFooter="True">
None.gif                    
<SelectedItemStyle ForeColor="GhostWhite" BackColor="DarkSlateBlue"></SelectedItemStyle>
None.gif                    
<AlternatingItemStyle BackColor="PaleGoldenrod"></AlternatingItemStyle>
None.gif                    
<HeaderStyle Font-Bold="True" BackColor="Tan"></HeaderStyle>
None.gif                    
<FooterStyle BackColor="Tan"></FooterStyle>
None.gif                    
<Columns>
None.gif                        
<asp:BoundColumn DataField="StudentID" ReadOnly="True" HeaderText="学生ID"></asp:BoundColumn>
None.gif                        
<asp:BoundColumn DataField="StudentName" HeaderText="学生姓名"></asp:BoundColumn>
None.gif                        
<asp:BoundColumn DataField="StudentPass" HeaderText="密码"></asp:BoundColumn>
None.gif                        
<asp:BoundColumn DataField="Sex" HeaderText="性别"></asp:BoundColumn>
None.gif                        
<asp:BoundColumn DataField="Birthday" HeaderText="生日" DataFormatString="{0:yyyy-M-d}"></asp:BoundColumn>
None.gif                        
<asp:BoundColumn DataField="Email" HeaderText="邮件地址"></asp:BoundColumn>
None.gif                        
<asp:BoundColumn DataField="Score" HeaderText="分数"></asp:BoundColumn>
None.gif                    
</Columns>
None.gif                    
<PagerStyle HorizontalAlign="Center" ForeColor="DarkSlateBlue" BackColor="PaleGoldenrod"></PagerStyle>
None.gif                
</asp:DataGrid></FONT>
None.gif        
</form>
None.gif    
</body>
None.gif
</HTML>
None.gif

后台代码:cs
None.gifusing System;
None.gif
using System.Collections;
None.gif
using System.ComponentModel;
None.gif
using System.Data;
None.gif
using System.Drawing;
None.gif
using System.Web;
None.gif
using System.Web.SessionState;
None.gif
using System.Web.UI;
None.gif
using System.Web.UI.WebControls;
None.gif
using System.Web.UI.HtmlControls;
None.gif
using System.Data.SqlClient;
None.gif
namespace MsDataGrid
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// WebForm1 的摘要说明。
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class UserCount : System.Web.UI.Page
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
protected System.Web.UI.WebControls.DataGrid dgShow;
InBlock.gif    
InBlock.gif        
private void Page_Load(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
// 在此处放置用户代码以初始化页面
InBlock.gif
            if(!IsPostBack)
InBlock.gif                BindData();
InBlock.gif            
InBlock.gif            
ExpandedSubBlockEnd.gif        }

InBlock.gif        
private void BindData()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
string strCon = System.Configuration.ConfigurationSettings.AppSettings["DSN"];
InBlock.gif            SqlConnection con 
= new SqlConnection(strCon);
InBlock.gif            SqlDataAdapter da 
= new SqlDataAdapter("Select * from tbStudentinfo",con);
InBlock.gif            DataSet ds 
= new DataSet();
InBlock.gif            da.Fill(ds,
"studentinfo");
InBlock.gif            dgShow.DataSource 
= ds.Tables["studentinfo"].DefaultView;
InBlock.gif            dgShow.DataBind();
InBlock.gif            
//以下作分数和的统计
InBlock.gif
            int count=0;
InBlock.gif            
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                count 
+= int.Parse(ds.Tables[0].Rows[i]["Score"].ToString());
ExpandedSubBlockEnd.gif            }

InBlock.gif            
int nAv = count/ds.Tables[0].Rows.Count;
InBlock.gif            
foreach(DataGridItem dgi in dgShow.Controls[0].Controls)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (dgi.ItemType == ListItemType.Footer)
InBlock.gif                    dgi.Cells[
6].Text = "平均:"+nAv.ToString();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
ExpandedSubBlockEnd.gif        }

ContractedSubBlock.gifExpandedSubBlockStart.gif        
Web Form Designer generated code#region Web Form Designer generated code
InBlock.gif        
override protected void OnInit(EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//
InBlock.gif            
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
InBlock.gif            
//
InBlock.gif
            InitializeComponent();
InBlock.gif            
base.OnInit(e);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
InBlock.gif        
/// 此方法的内容。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private void InitializeComponent()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{    
InBlock.gif            
this.Load += new System.EventHandler(this.Page_Load);
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
InBlock.gif        
InBlock.gif
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

转载于:https://www.cnblogs.com/ghd258/archive/2005/10/12/253193.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/464501.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Window系统下安装Redis

下载Redis Redis官网只提供Linux版本&#xff0c;Windows版本只能去GitHub上下载 Redis官网下载地址&#xff1a;http://redis.io/download GitHub下载地址&#xff1a;https://github.com/MSOpenTech/redis/tags 安装Redis 创建redis文件夹&#xff0c;解压到此目录下&#xf…

iTunes“解决方案”发展历程及研究(上)

以下内容来自于我的《iTunes内容解决方案研究》的PPT&#xff0c;懒得往上敲字了&#xff0c;直接以图片的形式发布&#xff0c;有需要的&#xff0c;我可以提供pdf版本给你&#xff0c;版权所有

java原生方法,Java Servlet原生调用方法过程简化

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼初学java web之后&#xff0c;了解了jsp跟Servlet交互的过程。具体过程如下&#xff1a;创建一个servlet&#xff0c;并重写doPost和doGer方法在MXL文件中配置servlet的接收请求的路径在jsp中请求该路径在servlet中写一个方法&…

Linux下的memcpy函数

之前写过一篇关于 memcpy函数面试的文章几个简单的笔试题里面的代码使用的是char指针来实现&#xff0c;今天我们来看看Linux下面的memcpy函数&#xff0c;它的实现上还是有一些巧妙的。void * memcpy(void * dest, const void *src, size_t n) {if (!(((unsigned long) dest ^…

extern关键字讲解

基本解释   extern可以置于变量或者函数前&#xff0c;以标示变量或者函数的定义在别的文件中&#xff0c;提示编译器遇到此变量和函数时在其他模块中寻找其定义。   另外&#xff0c;extern也可用来进行链接指定。 2 问题&#xff1a;extern 变量   在一个源文件里定义了…

日志钩子(JournalRecord Hook)的使用

-- 钩子是WINDOWS中消息处理机制的一个要点&#xff0c;通过安装各种钩子&#xff0c;应用程序能够设置相应的子例程来监视系统里的消息传递以及在这些消息到达目标窗口程序之前处理它们。钩子的种类很多&#xff0c;每种钩子可以截获并处理相应的消息&#xff0c;如键盘钩子可…

优先队列

CSTL——优先队列 一、相关定义 优先队列容器与队列一样&#xff0c;只能从队尾插入元素&#xff0c;从队首删除元素。但是它有一个特性&#xff0c;就是队列中最大的元素总是位于队首&#xff0c;所以出队时&#xff0c;并非按照先进先出的原则进行&#xff0c;而是将当前队列…

linux命令行抓取网页快照-(xvfb+CutyCapt)

linux命令行抓取网页快照-&#xff08;xvfbCutyCapt&#xff09;又一个 WordPress 博客Browse: Home / 2009 / 十一月 / linux命令行抓取网页快照-&#xff08;xvfbCutyCapt&#xff09;linux命令行抓取网页快照-&#xff08;xvfbCutyCapt&#xff09;By saymoon on 2009年11月…

php过waf木马,一款过waf的一句话木马分析 | CN-SEC 中文网

摘要中午&#xff0c;下班回来&#xff0c;就看一个朋友给我发了几个马儿 让我看看解解密码 很简单中午&#xff0c;下班回来&#xff0c;就看一个朋友给我发了几个马儿 让我看看解解密码 很简单猛不猛我不知道 那时候手机 太长的看着就烦 就回到家瞅瞅了首先我们看这…

你没干什么坏事,你怕什么?

如图我很久就知道深信服这家企业&#xff0c;记得是几年前&#xff0c;我有一个同学跟我说&#xff0c;有一个比较厉害的朋友在这个企业上班&#xff0c;拿到了非常不错的薪水&#xff0c;我如果想去这个公司看看&#xff0c;可以让这位朋友帮忙搭线。后面查这个企业&#xff0…

C++中的explicit关键字用法

c中的explicit关键字用来修饰类的构造函数&#xff0c;被修饰的类的构造函数不能进行隐式类型的转换&#xff0c;既然有"显式"那么必然就有"隐式"&#xff0c;那么什么是显示而什么又是隐式的呢&#xff1f; 如果c类的构造函数有一个参数&#xff0c;那么…

警告用户:VoIP电话存在诸多风险

IP电话是目前最为受欢迎的通信方式&#xff0c;但最近VoIP安全组织表示其拥有许多安全隐患。 该组织发布了一份IP电话供应商潜在的安全风险清单。旧式的公共开关网络电话&#xff08;PSTN&#xff09;并没有远离风险&#xff0c;而今VoIP也要加入这一风险行列。 秘密被偷听&…

织梦文章添加字段填栏目id,内容页调用字段里的栏目文章

在模型里增加个字段&#xff0c;然后在添加文章的时候&#xff0c;在字段里填了栏目id进去 在前台的内容页&#xff0c;调用这个字段栏目的多个文章出来 {dede:field.field1 runphpyes} global $dsql; $sql "select arc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault…

python用循环打出阶梯图形,matplotlib阶梯图的实现(step())

step函数概述step函数用于绘制阶梯图。根据源码可知&#xff0c;step函数是对plot函数的轻量级封装&#xff0c;很多概念和用法与plot函数非常相似。def step(self, x, y, *args, wherepre, dataNone, **kwargs):cbook._check_in_list((pre, post, mid), wherewhere)kwargs[dra…

xbmc addons

XBMC新版“扩展功能”简介 目录1. 扩展功能模块结构2. 图片文件指引 2.1 icon.png2.2 fanart.jpg3. addon.xml 3.1 <addon>元素3.2 <requires>元素3.3 <extension>元素3.4 xbmc.addon.metadata extension4. extension类别本贴介绍将在即将发布的XBMC Dharma&…

嵌入式还有哪些风口值得入?

大家好&#xff0c;我是写代码的篮球球痴前两天发了篇文章说到嵌入式薪资的&#xff0c;很多人想知道目前有哪些不错的行业可以加入&#xff0c;这篇文章罗列了很多风口行业。我相信&#xff0c;半导体芯片会是很重要的方向&#xff0c;但是不管路修得多好&#xff0c;都需要汽…

两个学习指针的例子

下面的结果是多少&#xff1f; int a5; int *example1(int b) { ab; return &a; } int *example2(int b) { int c5; bc; return &b; } void main() { int *a1example1(10); int *b1example2(10); cout <<”a1”<<*a1; cout <<”b1”<&l…

java 统计单词个数和标点符号

把随机输入的一句话比如:Its only a test!存放在一个char[]的数组中&#xff0c;统计char[]中的单词个数和标点符号的个数。 package com.faintbear; import java.io.*; publicclassTest{ public static void main(String[] args) throws Exception{ BufferedReade…

Luogu 4244 [SHOI2008]仙人掌图

BZOJ 1023 如果我们把所有的环都缩成一个点&#xff0c;那么整张图就变成了一棵树&#xff0c;我们可以直接$dp$算出树的直径。 设$f_x$表示$x$的子树中最长链的长度&#xff0c;那么对于$x$的每一个儿子$y$&#xff0c;先用$f_x f_y 1$更新答案&#xff0c;再用$f_y 1$更新…

trim的返回值php,php trim()函数

(1)trim()函数。该函数可以去除字符串开始位置以及结束位置的空格&#xff0c;并返回去掉空格后的字符串。该函数声明如下&#xff1a;string trim ( string str [, string charlist])默认的情况下&#xff0c;该函数去除的字符如下。" " (ASCII 32 码为(0x20))&…