惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Fortinet All Blogs
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
有赞技术团队
有赞技术团队
www.infosecurity-magazine.com
www.infosecurity-magazine.com
大猫的无限游戏
大猫的无限游戏
爱范儿
爱范儿
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Threatpost
V
Visual Studio Blog
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - Franky
人人都是产品经理
人人都是产品经理
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
The Cloudflare Blog
N
News and Events Feed by Topic
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
酷 壳 – CoolShell
酷 壳 – CoolShell
V
V2EX
AWS News Blog
AWS News Blog
S
SegmentFault 最新的问题
T
Tailwind CSS Blog
Hugging Face - Blog
Hugging Face - Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Spread Privacy
Spread Privacy
J
Java Code Geeks
博客园 - 聂微东
T
Tor Project blog
宝玉的分享
宝玉的分享
博客园 - 叶小钗
Webroot Blog
Webroot Blog
博客园 - 【当耐特】
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
H
Heimdal Security Blog
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
MongoDB | Blog
MongoDB | Blog
I
InfoQ
Security Latest
Security Latest
Martin Fowler
Martin Fowler
Hacker News: Ask HN
Hacker News: Ask HN
P
Privacy International News Feed
C
CERT Recently Published Vulnerability Notes
Latest news
Latest news
雷峰网
雷峰网
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cisco Blogs
H
Help Net Security
L
LINUX DO - 最新话题
L
LINUX DO - 热门话题

博客园 - protorock

WPF:通过Window.DataContext实现窗口间传值 How to add dependency on a Windows Service AFTER the service is installed 实现泛型IEnumerable接口 关于Local System/Local Service/Network Service账户 vs2010 c# 管理win7防火墙 WIN7系统中连接点(Junction Points) 程序集强名称(Strong Name)延迟签名与签名 VISUAL STUDIO 2010 单元测试 Windows Server 2008 R2上Ext.net 生产环境搭建 在Windows7 (SP1)配置IIS7.5 + .Net Framework 4.0.30319 将Google Map 与ASP.NET AJAX 扩展集成 web.config 加密步骤 - protorock - 博客园 在Windows 2003 中发布 ASP.NET 2.0 + SQL SERVER Express SQL Server 2005 Express Edition 用户实例 在 windows2003 Server VS2005 安装 .Net 3.0 .net framework 2.0,3.0与3.5之间的关系 SharpMap AjaxMapControl 中 Zoomin/Zoomout 操作时冻结问题 Sharpmap AjaxMapControl 分析 HTTP 协议概要(二) 持久连接
GridView 与自定义对象的绑定和分页
protorock · 2008-03-04 · via 博客园 - protorock

一、自定义对象和对象集合

using System;
using System.Collections;
using System.Collections.Generic;


/// <summary>
/// 手机模块定位
/// </summary>

public class Bus
{
    
public Bus(string name, float longitude, float latitude)
    
{
        
this.name = name;
        
this.latitude = latitude;
        
this.longitude = longitude;
    }


    
string name;
    
float longitude, latitude;

    
public string Name
    
{
        
get return name; }
    }


    
public float Longitude
    
{
        
get return longitude; }
    }


    
public float Latitude
    
{
        
get return latitude; }
    }

}



/// <summary>
/// 手机模块集合
/// </summary>

public class BusCollection
{
    List
<Bus> col;

    
public BusCollection()
    
{
        col 
= new List<Bus>();
        
for (int i = 0; i < 500; i++)
        
{
            Bus b 
= new Bus("13501401" + i.ToString("d3"), 118.333f32.1123f);
            col.Add(b);
        }

    }



    
public List<Bus> Collection
    
{
        
get return col; }
    }

}


二、页面表现逻辑

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    
<title>自定义对象绑定与分页</title>
    
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
    
<form id="form1" runat="server">
    
<div>
        
<asp:GridView ID="GridView1" 
            runat
="server" 
            AutoGenerateColumns
="False" 
            CssClass
="class2" 
            EnableViewState
="False" 
            AllowPaging
="true" 
            OnPageIndexChanging
="GridView1_PageIndexChanging">
            
<Columns>
                
<asp:BoundField DataField="Name" HeaderText="手机号码" />
                
<asp:BoundField DataField="Longitude" DataFormatString="{0:0.00000}" HeaderText="经度" />
                
<asp:BoundField DataField="Latitude" DataFormatString="{0:0.00000}" HeaderText="纬度" />
            
</Columns>
        
</asp:GridView>
    
</div>
    
</form>
</body>
</html>


后台代码

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
    
protected void Page_Load(object sender, EventArgs e)
    
{
        
if (!IsPostBack)
        
{
            DataBind();
        }

    }

    
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    
{
        GridView1.PageIndex 
= e.NewPageIndex;
        DataBind();
    }



    
private void DataBind()
    
{
        BusCollection c 
= new BusCollection();
        GridView1.DataSource 
= c.Collection;
        GridView1.DataBind();
    }

}


样式表StyleSheet.css

*
{
    font
-size: 9pt;
    font
-family: Verdana, 宋体, Tahoma;
}


.class2
{
    border
-collapse:collapse; 
    border: solid 2px #
336666;
}


.class2 td
{
    padding: 5px 10px;
    border: solid 1px #dcdcdc;
    
}

.class2 th
{
    background
-color: #336666;
    color: #ffffff;
    height: 
2.5em;
}