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