XP 风格的可拖动列、排序的DataGrid的例子
2024-07-21 02:23:11
供稿:网友
本文介绍xp 风格的可拖动列、排序的datagrid的例子,请查看
要想使用本源代码,请先下载如下文件:
downarrow.gif
sortblank.gif
sortup.gif
sortdown.gif
uparrow.gif
xptable.css
xptable.htc
源代码如下:【c#版本】
dragablexpstyletable.aspx
<%@ page language="c#" codebehind="dragablexpstyletable.aspx.cs"
autoeventwireup="false" inherits="emeng.exam.dragablexpstyletable.dragablexpstyletable" %>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en" >
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>xp 风格的可拖动列、排序的datagrid的例子</title>
<meta name="generator" content="microsoft visual studio 7.0">
<meta name="code_language" content="c#">
<link rel="stylesheet" type="text/css" href="xptable.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:20px"><b>xp 风格的可拖动列、排序的datagrid的例子。</b></div>
<asp:datagrid id="xptable" runat="server" autogeneratecolumns="false" cellpadding="2"
borderwidth="0" borderstyle="none" style="border-collapse:separate" width="90%" cssclass="xptable">
<headerstyle horizontalalign="center"></headerstyle>
<columns>
<asp:boundcolumn itemstyle-height="22" datafield="title" sortexpression="title"
headertext="文章标题"
headerstyle-font-bold="true"></asp:boundcolumn>
<asp:boundcolumn datafield="createdate" sortexpression="createdate"
headertext="创建日期" headerstyle-font-bold="true"
dataformatstring="{0:yyyy年mm月dd日 hh:mm:ss}"></asp:boundcolumn>
<asp:boundcolumn datafield="subtitle" sortexpression="subtitle"
headertext="所属栏目" headerstyle-font-bold="true"></asp:boundcolumn>
</columns>
</asp:datagrid>
</form>
</body>
</html>
dragablexpstyletable.aspx.cs
using system;
using system.collections;
using system.componentmodel;
using system.data;
using system.drawing;
using system.web;
using system.web.sessionstate;
using system.web.ui;
using system.web.ui.webcontrols;
using system.web.ui.htmlcontrols;
using system.data.oledb;
namespace emeng.exam.dragablexpstyletable
{
/// <summary>
/// dragablexpstyletable 的摘要说明。
/// xp风格的可拖动的datagrid
/// </summary>
public class dragablexpstyletable : system.web.ui.page
{
protected system.web.ui.webcontrols.datagrid xptable;
private void page_load(object sender, system.eventargs e)
{
// 在此处放置用户代码以初始化页面
xptable.attributes.add("altrowcolor","oldlace");
xptable.attributes.add("align","center");
string cnstring = "provider=microsoft.jet.oledb.4.0;data source=";
cnstring += system.web.httpcontext.current.server.mappath("testtable.mdb")
oledbconnection cn = new oledbconnection(cnstring);
cn.open();
cnstring = "select top 15 d.title,d.createdate,s.title as subtitle ";
cnstring += "from document d,subject s where d.pid=s.id order by d.createdate desc";
oledbcommand cmd = new oledbcommand(cnstring,cn);
xptable.datasource=cmd.executereader(commandbehavior.closeconnection);
xptable.databind();
cmd.dispose();
cn.close();
cn.dispose();
cn = null;
}
#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
}
}