dataGrid在页面拖动(用表头),不刷新页面

前台文件
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</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">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
   <asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 16px" runat="server"
    BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="4"
    Font-Size="9pt">
    <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>
/// WebForm1 的摘要说明。
/// </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);
}

/// <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 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
}
}


脚本文件:
/**
* <p>Title: dataGrid在页面拖动(用表头,不刷新页面)</p>
* <p>Description: 实现dataGrid在页面拖动(用表头,不刷新页面)</p>
* <p>Copyright: 2005-2005 by mail_ricklee Corporation</p>
* <p>Company: mail_ricklee Corporation</p>
* <p>CreateTime: 2005-04-17 21:30</p>
* <p>ModifyTime:                 </p>
* @CreateAuthor 李淼    * @version 1.0
* @ModifyAuthor         * @version 1.0
*/
<SCRIPT LANGUAGE="JavaScript">
<!--
var currentMoveObj = null;    //当前拖动对象
var relLeft;    //鼠标按下位置相对对象位置
var relTop;
function f_mdown(obj)
{
    currentMoveObj = obj;        //当对象被按下时,记录该对象
    currentMoveObj.style.position = "absolute";
    relLeft = event.x - currentMoveObj.style.pixelLeft;
    relTop = event.y - currentMoveObj.style.pixelTop;
}
window.document.onmouseup = function()
{
    currentMoveObj = null;    //当鼠标释放时同时释放拖动对象
}
function f_move(obj)
{
    if(currentMoveObj != null)
    {
        currentMoveObj.style.pixelLeft=event.x-relLeft;
        currentMoveObj.style.pixelTop=event.y-relTop;
    }
}

//-->
</SCRIPT>

转载于:https://www.cnblogs.com/jixiaozeng/archive/2012/08/14/2637709.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值