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

80酷酷网    80kuku.com

  datagrid|htc|页面

#region 声明
//----------------------------------------------------------------------
//
// 修改: 李淼(Nick.Lee)
//
// dataGrid在页面拖动行(在表头,用htc文件实现)

// 时间:2005-04-23

// boyorgrilmsn.com
// boyorgrilhotmail.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 "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>

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

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: