分享
 
 
 

[原创]dataGrid在页面拖动行(在表头,用htc文件实现)

王朝c#·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

#region 声明

//----------------------------------------------------------------------

//

// 修改: 李淼(Nick.Lee)

//

// dataGrid在页面拖动行(在表头,用htc文件实现)

// 时间:2005-04-23

// boyorgril@msn.com

// boyorgril@hotmail.com

// QQ:16503096

//注意:引用请标明修改出处,谢谢

//----------------------------------------------------------------------

#endregion

前台页面

<%@ Page language="c#" Codebehind="WebForm5.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm5" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >

<HTML>

<HEAD>

<title>WebForm5</title>

<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">

<meta name="CODE_LANGUAGE" Content="C#">

<meta name="vs_defaultClientScript" content="JavaScript">

<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">

<LINK href="xpTable.css" type="text/css" rel="stylesheet">

</HEAD>

<body>

<form id="Form1" method="post" runat="server">

<asp:DataGrid id="DataGrid1" runat="server" Font-Size="9pt" CellPadding="4" style="BEHAVIOR:url(grid.htc)"

BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" BackColor="White">

<SelectedItemStyle Font-Bold="True" ForeColor="#663399" BackColor="#FFCC66"></SelectedItemStyle>

<ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>

<HeaderStyle Font-Bold="True" ForeColor="#FFFFCC" BackColor="#990000"></HeaderStyle>

<FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>

<PagerStyle HorizontalAlign="Center" ForeColor="#330099" BackColor="#FFFFCC"></PagerStyle>

</asp:DataGrid>

</form>

</body>

</HTML>

后台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;

namespace WebApplication1

{

/// <summary>

/// WebForm5 的摘要说明。

/// </summary>

public class WebForm5 : System.Web.UI.Page

{

protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;

protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;

protected System.Data.SqlClient.SqlConnection sqlConnection1;

protected WebApplication1.DataSet1 dataSet11;

protected System.Web.UI.WebControls.DataGrid DataGrid1;

private void Page_Load(object sender, System.EventArgs e)

{

// 在此处放置用户代码以初始化页面

sqlDataAdapter1.Fill(this.dataSet11);

this.DataGrid1.DataSource=this.dataSet11.Tables[0];

this.DataBind();

}

#region Web 窗体设计器生成的代码

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。

//

InitializeComponent();

base.OnInit(e);

}

/// <summary>

/// 设计器支持所需的方法 - 不要使用代码编辑器修改

/// 此方法的内容。

/// </summary>

private void InitializeComponent()

{

this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();

this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();

this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();

this.dataSet11 = new WebApplication1.DataSet1();

((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();

//

// sqlDataAdapter1

//

this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;

this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {

new System.Data.Common.DataTableMapping("Table", "Categories", new System.Data.Common.DataColumnMapping[] {

new System.Data.Common.DataColumnMapping("CategoryID", "CategoryID"),

new System.Data.Common.DataColumnMapping("CategoryName", "CategoryName"),

new System.Data.Common.DataColumnMapping("Description", "Description"),

new System.Data.Common.DataColumnMapping("Picture", "Picture")})});

//

// sqlSelectCommand1

//

this.sqlSelectCommand1.CommandText = "SELECT CategoryID, CategoryName, Description, Picture FROM Categories";

this.sqlSelectCommand1.Connection = this.sqlConnection1;

//

// sqlConnection1

//

this.sqlConnection1.ConnectionString = "workstation id=\"STAR-NICK\";packet size=4096;user id=sa;data source=\"(local)\";pers" +

"ist security info=False;initial catalog=Northwind;pwd=sa;";

//

// dataSet11

//

this.dataSet11.DataSetName = "DataSet1";

this.dataSet11.Locale = new System.Globalization.CultureInfo("zh-CN");

this.Load += new System.EventHandler(this.Page_Load);

((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();

}

#endregion

}

}

grid.htc文件:

/**

* <p>Title: dataGrid在页面拖动行(在表头,用htc文件实现)</p>

* <p>Description: dataGrid在页面拖动行(在表头,用htc文件实现)</p>

* <p>Copyright: 2005-2005 by mail_ricklee Corporation</p>

* <p>Company: mail_ricklee Corporation</p>

* <p>CreateTime: 2005-04-23 21:30</p>

* <p>ModifyTime: </p>

* @CreateAuthor 李淼 * @version 1.0

* @ModifyAuthor * @version 1.0

*/

<PUBLIC:COMPONENT>

<PUBLIC:ATTACH EVENT="oncontentready" ONEVENT="fnInit()" />

<PUBLIC:ATTACH EVENT="onclick" ONEVENT="fnClick()" />

<METHOD NAME="menubarpush"/>

<SCRIPT LANGUAGE="JScript">

function fnInit()

{

for(var i=0;i<element.rows.length;i++)

{

var _tr = element.rows[i];

for(var j=0;j<_tr.cells.length;j++)

{

if(i==0)

{

_tr.attachEvent("onmousedown", fnMousedown);

_tr.attachEvent("onmousemove",fnMousemove);

_tr.attachEvent("onmouseover",fnMouseover);

_tr.attachEvent("onselectstart",fnCancel);

window.document.attachEvent("onmouseup", fnMouseup);

window.document.attachEvent("onmousemove",fnMouseMove);

}

}

}

var _line = window.document.createElement("DIV");

_line.style.position = "absolute";

_line.style.backgroundColor="Silver";

_line.style.width=1;

window.document.body.appendChild(_line);

element.splitLine = _line;

element.splitLine.style.display = "none";

}

function fnMouseover()

{

return;

}

function fnMouseMove(){

if(!element.splitlocked) return;

fnMousemove();

}

function fnMousemove(){

var oEl = event.srcElement;

element.splitLine.style.left = window.event.x;

element.splitLine.style.top = getTop(element);

element.splitLine.style.height = element.parentElement.clientHeight;

if(element.splitlocked) return;

if(!IfSplitLocation(oEl)) return;

}

function fnClick(){

var oEl = event.srcElement;

}

function fnMousedown(){

var oEl = event.srcElement;

if(!IfSplitLocation(oEl)) return;

element.splitLine.style.display = "";

element.splitlocked = true;

window.document.attachEvent("onselectstart",fnCancel);

}

function fnMouseup()

{

element.splitLine.style.display = "none";

element.splitlocked = false;

element.document.body.style.cursor='default';

if(element.curResizeTD == null) return;

var otd = element.curResizeTD;

var otdLeft = getLeft(otd);

var otdwidth = element.splitLine.style.pixelLeft - otdLeft

if(otdwidth < 0) return;

otd.style.width = otdwidth;

window.document.detachEvent("onselectstart",fnCancel);

}

function IfSplitLocation(oEl)

{

if(oEl.tagName == "DIV")

oEl = oEl.parentElement;

if(oEl.tagName == "TD")

{

if(Math.abs(event.offsetX - oEl.clientWidth) <= 5)

{

element.curResizeTD = oEl;

element.document.body.style.cursor='col-resize';

}

else if (Math.abs(event.offsetX) <= 5 && oEl.cellIndex>0){

if(oEl.cellIndex>0){

element.curResizeTD = oEl.parentElement.cells(oEl.cellIndex-1);

element.document.body.style.cursor='col-resize';

}

}

else{

element.curResizeTD = null;

element.document.body.style.cursor='default';

return false;

}

}

return true;

}

function getTop(e){

var t=e.offsetTop;

while(e=e.offsetParent){

t+=e.offsetTop;

}

return t;

}

function getLeft(e){

var l=e.offsetLeft;

while(e=e.offsetParent){

l+=e.offsetLeft;

}

return l;

}

function fnCancel()

{

window.event.returnValue = false;

return false;

}

</SCRIPT>

</PUBLIC:COMPONENT>

新修改了拖动线和去掉边框^_^

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有