1.前台代码

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication15.WebForm1" %>

<%@ Register Assembly="DevExpress.Web.v15.1, Version=15.1.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web" TagPrefix="dx" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False">

<SettingsPager PageSize="30" Position="TopAndBottom" SEOFriendly="Enabled" >
</SettingsPager>
<Settings ShowGroupPanel="True" ShowGroupFooter="VisibleAlways"></Settings>
<SettingsBehavior AllowFixedGroups="False" AllowGroup="True" AllowDragDrop="True"/>

<Columns>

<dx:GridViewDataTextColumn FieldName="No" UnboundType="Integer" VisibleIndex="1">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="Name" UnboundType="String" VisibleIndex="2">

</dx:GridViewDataTextColumn>

</Columns>

<GroupSummary>
<dx:ASPxSummaryItem DisplayFormat="合计:0" FieldName="Name" SummaryType="Sum" />
</GroupSummary>

</dx:ASPxGridView>
</div>
</form>
</body>
</html>

2.后台代码

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication15
{
public class Student
{
public int No { get; set; }
public int Name { get; set; }
}

public static class ListAndTableExt
{
public static DataTable ToDataTable<T>(this List<T> list) where T : class, new()
{
DataColumn column = null;
DataTable table = new DataTable();
List<PropertyInfo> ps = typeof(T).GetProperties().ToList();
ps.ForEach(p =>
{
if (!p.PropertyType.IsGenericType)
{
column = new DataColumn(p.Name, p.PropertyType);
}
else
{
if (p.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
{
column = new DataColumn(p.Name, Nullable.GetUnderlyingType(p.PropertyType));
}
}
if (column != null)
{
table.Columns.Add(column);
}
});
list.ForEach(obj =>
{
DataRow row = table.NewRow();
ps.ForEach(p =>
{
row[p.Name] = p.GetValue(obj, null);
});
table.Rows.Add(row);
});
return table;
}

public static List<T> ToList<T>(this DataTable table) where T : class, new()
{
List<PropertyInfo> ps = typeof(T).GetProperties().ToList();
List<T> list = new List<T>();
foreach (DataRow row in table.Rows)
{
T obj = new T();
foreach (DataColumn col in table.Columns)
{

ps.ForEach(p =>
{
if (p.Name == col.ColumnName)
{
if (!p.PropertyType.IsGenericType)
{
p.SetValue(obj, string.IsNullOrEmpty(row[p.Name].ToString()) ? null : Convert.ChangeType(row[p.Name].ToString(), p.PropertyType));

}
else
{
if (p.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
{
p.SetValue(obj, string.IsNullOrEmpty(row[p.Name].ToString()) ? null : Convert.ChangeType(row[p.Name], Nullable.GetUnderlyingType(p.PropertyType)));

}
}
}
});
}
list.Add(obj);

}
return list;

}

}
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
List<Student> stuList = new List<Student>();
for (int i = 0; i < 100; i++)
{
stuList.Add(new Student() { No = i, Name = i });
}
stuList.Add(new Student() { No = 1, Name = 22 });
stuList.Add(new Student() { No = 1, Name = 33 });

DataTable table = stuList.ToDataTable();
ASPxGridView1.DataSource = table;
ASPxGridView1.DataBind();
List<Student> students = table.ToList<Student>();

}
}
}

dev初识 拖动分组的更多相关文章

  1. dev gridview 设置分组

    private void GridConfig() { GridGroupSummaryItem item = new GridGroupSummaryItem(); item.FieldName = ...

  2. 手把手教从零开始在GitHub上使用Hexo搭建博客教程(三)-使用Travis自动部署Hexo(1)

    前言 前面两篇文章介绍了在github上使用hexo搭建博客的基本环境和hexo相关参数设置等. 基于目前,博客基本上是可以完美运行了. 但是,有一点是不太好,就是源码同步问题,如果在不同的电脑上写文 ...

  3. 跟我一起学extjs5(19--模块记录的拖放删除、拖放复制新增)

    跟我一起学extjs5(19--模块记录的拖放删除.拖放复制新增)         网页其中的拖放(drag-drop)是比較有趣的操作,extjs5中非常好的封装了拖放的动作,也有各种类来支持,可是 ...

  4. 18、手把手教你Extjs5(十八)模块记录的拖放删除、拖放复制新增

    网页当中的拖放(drag-drop)是比较有趣的操作,extjs5中很好的封装了拖放的动作,也有各种类来支持,但是要学好“拖放”这个东西真是很难,特别是象我这样英语不好的人,看不太懂官网上的说明,做一 ...

  5. C#实现DevExpress本地化实例详解

    using System; using System.Collections.Generic; using System.Text; using DevExpress.XtraGrid.Localiz ...

  6. ArchLinux安装步骤(一)

    本文为安装archlinux的教程,需要有硬盘分区,挂载等基础linux命令的了解还有vim的基本操作,不知道也没关系,这里有大神的视频教程ArchLinux指南. 确实是不是uefi模式 ls /s ...

  7. 18-Spring Cloud Alibaba Nacos

    简介 为什么叫Nacos 前四个字母分别为Naming和Configuration的前两个字母,最后的s为Service Nacos是什么 一个更易于构建云原生应用的动态服务发现.配置管理和服务管理平 ...

  8. 耗时半年,Eoapi 终于正式发布 API 工具的插件广场

      这是我们的第一篇月报,每个月和每个来之不易的开发者分享产品故事以及产品进展. 在 5.20 这个极具中国特色的"节日"里,Eoapi 发布了 1.0.0 版,三个程序员掉了半年 ...

  9. Dev用于界面按选中列进行分组统计数据源(实用技巧)

    如果有用U8的可以明白这个功能就是模仿他的统计功能.我不过是把他造成通用的与适应于DEV的. (效率为6000条数据分组统计时间为3秒左右分组列过多5秒.1000条以下0.几秒,500条下0.00几秒 ...

随机推荐

  1. 十六、python沉淀之路--迭代器

    一.迭代器 1.什么是迭代器协议:对象必须提供一个next方法,执行该方法要返回迭代中的下一项,要么就引起一个StopIteration异常,以终止迭代(只能往后走,不能往前走). 2.可迭代对象:实 ...

  2. Google网站遭到域名劫持

    今天晚上,包括Google.com在内的绝大多数Google国际网站,例如Google.com.Gmail.Google Reader.Google Docs等,在中国部分省市均出现无法访问的情况. ...

  3. 数据库中通过group by找出表中的重复数据

    有时候在做数据割接时会碰到数据插入失败的情况,大部分都是导出的数据中存在重复导致的.我们可以通过查询语句带分组条件来确认是否有重复数据.例如我现在有表 t_wlf_info,其中有个 username ...

  4. mysql5.7不支持0000-00-00 00:00:00的默认时间设置

    方案一: 数据不多的话把原有的5.53的数据改一下符合要求(数据库时间字段里千万不能出现0000-00-00 00:00:00这样的值),然后导出.sql文件,导出的.sql文件里把 DEFAULT ...

  5. laravel中有条件使用where

    在项目开发的过程中;有时候会有多个参数 去用在where查询中;那么这里的where语句是可能有也可能没有的 1.用原生的mysql语句来实现 private function getData($ty ...

  6. classpath和环境变量设置

    一.简介: 环境变量是操作系统.应用程序.脚本程序等等的指明灯,能够告诉他们需要的资源在哪里.大多数的 系统都有一些预先设置好的环境变量,当然,我们也可以增加自己的环境变量. 为了看看当前系统的环境变 ...

  7. PTA 是否同一棵二叉搜索树(25 分)

    是否同一棵二叉搜索树(25 分) 给定一个插入序列就可以唯一确定一棵二叉搜索树.然而,一棵给定的二叉搜索树却可以由多种不同的插入序列得到.例如分别按照序列{2, 1, 3}和{2, 3, 1}插入初始 ...

  8. PHP 字符串 加*

    PHP字符串加* 思路: 获取第一个字符或文字 获取最后一个字符或文字 一头一尾,中间加* 尝试用substr方法,发现对中文的支持有问题. 后来发现mb_substr很好的解决了这个问题. < ...

  9. 在rac集群上开启OEM

    由于安装rac的时候没有开启oem,这里开启oem,方便管理 [oracle@rac01 ~]$ emca -config dbcontrol db -repos create -cluster ST ...

  10. C# winform程序免安装.net framework在XP/win7/win10环境运行!(转)

    C# winform程序免安装.net framework在XP/win7/win10环境运行!   前文: 首先感谢群里的大神宇内流云 提供的anyexec for windows版本. 经过本人搭 ...