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

推荐订阅源

N
News | PayPal Newsroom
IT之家
IT之家
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
大猫的无限游戏
大猫的无限游戏
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
L
LangChain Blog
S
SegmentFault 最新的问题
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Project Zero
Project Zero
P
Privacy & Cybersecurity Law Blog
V
Vulnerabilities – Threatpost
博客园 - 三生石上(FineUI控件)
Recorded Future
Recorded Future
The Hacker News
The Hacker News
C
CXSECURITY Database RSS Feed - CXSecurity.com
C
CERT Recently Published Vulnerability Notes
宝玉的分享
宝玉的分享
aimingoo的专栏
aimingoo的专栏
T
Tor Project blog
T
The Exploit Database - CXSecurity.com
Schneier on Security
Schneier on Security
H
Help Net Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
M
MIT News - Artificial intelligence
W
WeLiveSecurity
P
Proofpoint News Feed
A
About on SuperTechFans
S
Securelist
I
InfoQ
G
Google Developers Blog
博客园 - 司徒正美
博客园 - 叶小钗
Latest news
Latest news
F
Fortinet All Blogs
G
GRAHAM CLULEY
腾讯CDC
Jina AI
Jina AI
S
Schneier on Security
I
Intezer
V
Visual Studio Blog
美团技术团队
V2EX - 技术
V2EX - 技术
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Cloudflare Blog
Microsoft Security Blog
Microsoft Security Blog
Blog — PlanetScale
Blog — PlanetScale
P
Proofpoint News Feed
罗磊的独立博客
Y
Y Combinator Blog

博客园 - 疾行者

关于开发ActiveX 控件的安装问题 [转]安卓巴士Android开发神贴整理 Ruby On Rails 安装手记 偶然发现5年前的编程实习日记,特与博客园同仁分享一下 实现客户端的DataSet - 疾行者 - 博客园 AutoIt应用技巧示例[转] - 疾行者 - 博客园 [导入]Linq学习笔记(1.7)——First、ElementAt、Any、all [导入]Linq学习笔记(1.8)——Count、Sum、Min、Max、Average [导入]Linq学习笔记(2.1)——初识 DLinq [导入]Linq学习笔记(2.2)——深入DLinq查询 [导入]Linq学习笔记(2.3)——DLinq高级操作 NHibernate 多主键设置 - 疾行者 - 博客园 c#的一些技巧 - 疾行者 - 博客园 人的一生,到底在追求甚么?... webservice结合dthml的简单例子(二,dhtml) 文件的上传下载 asp.net访问组件失败,请在web.,config中加 数字转化成大写类 javascript小技巧&&JavaScript[对象.属性]集锦 [转载了多篇]
XP 风格的可拖动列、可排序、可改变宽度的DataGrid的例子
疾行者 · 2006-10-31 · via 博客园 - 疾行者

利用客户端脚本的优势,我们可以创建出可以拖动列,改变列宽度,显示、隐藏列的XP风格的 DataGrid,下面就是所有的代码。自己调试时请注意修改eMeng.Exam.UltraGrid路径。

查看例子

UltraGrid.aspx

<%@ Page language="c#" Codebehind="UltraGrid.aspx.cs" AutoEventWireup="false" Inherits="eMeng.Exam.UltraGrid.UltraGrid" %> <!doctype HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <html> <head> <title>XP 风格的可拖动列、可排序、可改变宽度的DataGrid的例子</title> <meta http-equiv="content-type" content="text/html; charset=gb2312"> <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0"> <meta name="CODE_LANGUAGE" Content="C#"> <link rel="stylesheet" type="text/css" href="UltraGrid.css"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> </head> <body MS_POSITIONING="GridLayout"> <form id="DragableXpStyleTable" method="post" runat="server"> <div align="center" style="PADDING:5px"> <strong> XP 风格的可拖动列、可排序、可改变宽度的DataGrid的例子。</strong> </div> <div id="coolUltraGrid1" runat="server"> <div class="gridHead"> <div class="gridRow" id="gridRow" runat="server"></div> </div> <asp:literal id="RowItem" runat="server"></asp:literal> </div> </form> </body> </html>

UltraGrid.aspx.cs

using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Data.OleDb; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace eMeng.Exam.UltraGrid { /// <summary> /// UltraGrid 的摘要说明。本例子演示了如何创建可排序、可拖放、可调整宽度的XP风格的DataGrid。 /// 出自:【孟宪会之精彩世界】 /// </summary> public class UltraGrid : System.Web.UI.Page { protected System.Web.UI.HtmlControls.HtmlGenericControl gridRow; protected System.Web.UI.WebControls.Literal RowItem; protected System.Web.UI.HtmlControls.HtmlGenericControl coolUltraGrid1; private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 coolUltraGrid1.Attributes.Add("class","coolUltraGrid"); coolUltraGrid1.Attributes.Add("style","WIDTH: 100%; HEIGHT: 400"); coolUltraGrid1.Attributes.Add("borderStyle","2"); coolUltraGrid1.Attributes.Add("altRowColor","oldLace"); coolUltraGrid1.Attributes.Add("selectionStyle","1"); /// 请根据你的数据库的设置,修改这里的数据库连接字符串和查询语句。其它不要修改。 OleDbConnection cn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\xxx.mdb"); cn.Open(); string sqlstring = "SELECT TOP 30 D.Title As 文档标题,D.CreateDate as 发布时间,S.Title AS 所属栏目 "; sqlstring += "FROM Document D,Subject S WHERE D.pid=S.id ORDER BY D.CreateDate DESC"; OleDbCommand cmd = new OleDbCommand(sqlstring,cn); OleDbDataReader dr; dr=cmd.ExecuteReader(CommandBehavior.CloseConnection); /// ///组合表头 /// int FieldNumber = dr.FieldCount; int ColWidth,Tmp = 0; if(FieldNumber == 0) Response.End(); ColWidth = (int)100/FieldNumber; string TableHeader = ""; for(int i=0;i<fieldnumber;i++) { if(dr.Read()) { if(i==FieldNumber-1) TableHeader +="<span width='"+(100-Tmp).ToString()+"%'>"+dr.GetName(i).ToString()+"</span>"; else TableHeader +="<span width='"+ColWidth.ToString()+"%'>"+dr.GetName(i).ToString()+"</span>"; Tmp+=ColWidth; } } gridRow.InnerHtml=TableHeader; int RowNumber = 1; TableHeader = " <div class='gridBody'>"; while(dr.Read()) { TableHeader += " <div class='gridRow' id='row"+RowNumber.ToString()+"'>"; for(int i=0;i<fieldnumber;i++) { TableHeader +="<span>"+dr.GetValue(i).ToString()+"</span>"; } TableHeader += "</div> "; RowNumber++; } TableHeader += "</div> "; RowItem.Text=TableHeader; cn.Close(); } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); } /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } #endregion } }