The DataGrid drags rows on the page (implemented in the header, with HTC file)

Source: Internet
Author: User
Tags abs header tagname visual studio
datagrid|htc| page

#region Statement
//----------------------------------------------------------------------
//
Modified: Li Miao (nick.lee)
//
The DataGrid drags rows on the page (implemented in the header, with HTC file)

Time: 2005-04-23

Boyorgril@msn.com
Boyorgril@hotmail.com
qq:16503096
Note: Please indicate the source of the change, thank you
//----------------------------------------------------------------------
#endregion


Front Page
<%@ 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>
<footerstyle forecolor= "#330099" backcolor= "#FFFFCC" ></FooterStyle>
<pagerstyle horizontalalign= "Center" forecolor= "#330099" backcolor= "#FFFFCC" ></PagerStyle>
</asp:DataGrid>
</form>
</body>
</HTML>
Background CS File
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>
Summary description of the 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)
{
Place user code here to initialize page
SqlDataAdapter1.Fill (THIS.DATASET11);
This. Datagrid1.datasource=this.dataset11.tables[0];
This. DataBind ();
}

Code generated #region the Web forms Designer
Override protected void OnInit (EventArgs e)
{
//
CodeGen: This call is required for the ASP.net Web forms Designer.
//
InitializeComponent ();
Base. OnInit (e);
}

<summary>
Designer supports required methods-do not use the Code editor to modify
The contents of this method.
</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\ ";p acket size=4096;user id=sa;data source=\" ( local) \ ";p ers" +
"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 file:
/**
* <p>title:datagrid Drag rows in the page (in the header, with the HTC file implementation) </p>
* <p>description:datagrid Drag rows in the page (in the header, with the HTC file implementation) </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 Li Miao * @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>

The drag line and the border are removed ^_^ the new changes



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.