[原创]dataGrid在页面拖动(用表头),不刷新页面

#region 声明
//----------------------------------------------------------------------
//
// 修改: 李淼(Nick.Lee)
//
// dataGrid在页面拖动(用表头),不刷新页面

// 时间:2005-04-17

// [email protected]
// QQ:16503096
//注意:引用请标明修改出处,谢谢
//----------------------------------------------------------------------
#endregion
前台文件

1@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" 
 1<html>
 2<head>
 3<title>WebForm1</title>
 4<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR"/>
 5<meta content="C#" name="CODE_LANGUAGE"/>
 6<meta content="JavaScript" name="vs_defaultClientScript"/>
 7<meta content=" http://schemas.microsoft.com/intellisense/ie5 " name="vs_targetSchema"/>
 8</head>
 9<body ms_positioning="GridLayout">
10<form id="Form1" method="post" runat="server">
11<asp:datagrid backcolor="White" bordercolor="#CC9966" borderstyle="None" borderwidth="1px" cellpadding="4" font-size="9pt" id="DataGrid1" runat="server" style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 16px">
12<selecteditemstyle backcolor="#FFCC66" font-bold="True" forecolor="#663399"></selecteditemstyle>
13<itemstyle backcolor="White" forecolor="#330099"></itemstyle>
14<headerstyle backcolor="#990000" font-bold="True" forecolor="#FFFFCC"></headerstyle>
15<footerstyle backcolor="#FFFFCC" forecolor="#330099"></footerstyle>
16<pagerstyle backcolor="#FFFFCC" forecolor="#330099" horizontalalign="Center"></pagerstyle>
17</asp:datagrid>
18</form>
19</body>
20</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
{
///

1<summary>   
2/// WebForm1 的摘要说明。   
3/// </summary>

public class WebForm1 : System.Web.UI.Page
{
internal System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected WebApplication1.DataSet1 dataSet11;
// protected GorthControls.GridSlideHeader GridSlideHeader1;
// protected GorthControls.GridSlideHeader GridSlideHeader2;
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();
this.DataGrid1.Attributes.Add("onselectstart","return false");
this.DataGrid1.Attributes.Add("onmousedown","f_mdown(this)");
this.DataGrid1.Attributes.Add("onmousemove","f_move(this)");
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

///

1<summary>   
2/// 设计器支持所需的方法 - 不要使用代码编辑器修改   
3/// 此方法的内容。   
4/// </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 TOP 1 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
}
}

脚本文件:
/**
*

1<p>Title: dataGrid在页面拖动(用表头,不刷新页面)</p>
1<p>Description: 实现dataGrid在页面拖动(用表头,不刷新页面)</p>
1<p>Copyright: 2005-2005 by mail_ricklee Corporation</p>
1<p>Company: mail_ricklee Corporation</p>
1<p>CreateTime: 2005-04-17 21:30</p>
1<p>ModifyTime: </p>
  • @CreateAuthor 李淼 * @version 1.0
  • @ModifyAuthor * @version 1.0
    */
 1<script language="JavaScript">   
 2<!--   
 3var currentMoveObj = null; //当前拖动对象   
 4var relLeft; //鼠标按下位置相对对象位置   
 5var relTop;   
 6function f_mdown(obj)   
 7{   
 8currentMoveObj = obj; //当对象被按下时,记录该对象   
 9currentMoveObj.style.position = "absolute";   
10relLeft = event.x - currentMoveObj.style.pixelLeft;   
11relTop = event.y - currentMoveObj.style.pixelTop;   
12}   
13window.document.onmouseup = function()   
14{   
15currentMoveObj = null; //当鼠标释放时同时释放拖动对象   
16}   
17function f_move(obj)   
18{   
19if(currentMoveObj != null)   
20{   
21currentMoveObj.style.pixelLeft=event.x-relLeft;   
22currentMoveObj.style.pixelTop=event.y-relTop;   
23}   
24} 
25
26//-->   
27</script>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus