Implement DataGrid dragging and sorting

Source: Internet
Author: User

1. html <HTML>
<Head>
<Title> movedatagrid </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 = "behavior: URL (movegrid. HTC)" runat = "server" backcolor = "white"
Borderwidth = "1px" borderstyle = "NONE" bordercolor = "# cc9966" 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"> <Footerstyle forecolor = "#330099" backcolor = "# ffffcc"> </footerstyle>
<Pagerstyle horizontalalign = "center" forecolor = "#330099" backcolor = "# ffffcc"> </pagerstyle>
</ASP: DataGrid>
</Form>
</Body>
</Html>

2. CS

Public class movedatagrid: system. Web. UI. Page
{
Protected system. Web. UI. webcontrols. DataGrid datagrid1;
Private string constring = "";
Private int ncolumn = 0;
Private void page_load (Object sender, system. eventargs E)
{
String SQL = "select * From testgrid ";
Dataset DS = getdataset (SQL );
Datagrid1.attributes. Add ("dragcolor", "gray ");
Datagrid1.attributes. Add ("slcolor", "# ffffcc ");
Datagrid1.attributes. Add ("hlcolor", "# bec5de ");
Ncolumn = Ds. Tables [0]. Columns. count;
This. datagrid1.datasource = Ds;
This. datagrid1.databind ();
}


Getdataset # region getdataset
Private dataset getdataset (string SQL)
{
Constring = system. configuration. configurationsettings. deleetpipeline ["connectionstring"];
Sqldataadapter SDA = new sqldataadapter (SQL, constring );
Dataset DS = new dataset ();
SDA. Fill (DS );
Return Ds;
}
# Endregion

Web Form Designer generated code # region web form designer generated code
Override protected void oninit (eventargs E)
{
//
// Codegen: This call is required by the ASP. NET web form designer.
//
Initializecomponent ();
Base. oninit (E );
This. Maid + = new maid (maid itemcreated );
}

/** // <Summary>
/// Required method for designer support-do not modify
/// The contents of this method with the code editor.
/// </Summary>
Private void initializecomponent ()
{
This. Load + = new system. eventhandler (this. page_load );

}
# Endregion

Private void datagrid1_itemcreated (Object sender, datagriditemeventargs E)
{
If (E. Item. itemtype = listitemtype. header)
{
For (INT I = 0; I <ncolumn; I ++)
{
E. Item. cells [I]. Attributes. Add ("width", "200 ");
}
}
}
}

3. Download the source code/files/singw.ine/moveandsort.rar

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.