DevExpress Add ASPxGridView template columns at runtime
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"
Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="GridPlan.aspx.cs" Inherits="PlanTest.Layouts.PlanTest.GridPlan"
DynamicMasterPageFile="~masterurl/default.master" %> <%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxHiddenField" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxCallback" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v11.1, Version=11.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v11.1, Version=11.1.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dx" %>
<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
<script type="text/javascript" language="javascript">
function GetSaveData() {
var rowCount = gdv.GetVisibleRowsOnPage();
var valueStr = '';
var colNameStr = hdl.Get("colNames");
for (var i = 0; i < rowCount; i++) {
var colNames = new Array();
colNames = colNameStr.split(',');
var id = gdv.GetRowKey(i);
for (var j = 0; j < colNames.length; j++) {
var txtClientName = 'txt' + id + colNames[j];
var txtEditor = ASPxClientControl.GetControlCollection().GetByName(txtClientName);
valueStr = valueStr + txtEditor.GetText() + '&' + txtEditor.cpID + '|';
}
}
return valueStr;
}
</script>
</asp:Content>
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<dx:ASPxCallback ID="clb" runat="server" ClientInstanceName="clb" OnCallback="clb_OnCallback">
<ClientSideEvents CallbackComplete="function(s, e){
if(e.result=='0')
{
//error
alert('失败,联系管理员');
}
else
{
//yes
alert('成功');
gdv.Refresh();
}
}" />
</dx:ASPxCallback>
<dx:ASPxHiddenField ID="hdl" runat="server" ClientInstanceName="hdl">
</dx:ASPxHiddenField>
<dx:ASPxGridView ID="gdv" ClientInstanceName="gdv" runat="server" OnLoad="gdv_OnLoad"
KeyFieldName="ID">
<Columns>
<dx:GridViewDataColumn FieldName="Name" Caption="Name">
</dx:GridViewDataColumn>
<dx:GridViewDataColumn FieldName="Count" Caption="Count">
</dx:GridViewDataColumn>
</Columns>
</dx:ASPxGridView>
<dx:ASPxButton ID="btnTest" runat="server" Text="保存">
<ClientSideEvents Click="function(s, e){
clb.PerformCallback(GetSaveData());
e.processOnServer = false;
}" />
</dx:ASPxButton>
</asp:Content>
<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
应用程序页
</asp:Content>
<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea"
runat="server">
我的应用程序页
</asp:Content>
using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Web.UI;
using DevExpress.Web.ASPxEditors;
using DevExpress.Web.ASPxGridView;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using DevExpress.Web.ASPxCallback; namespace PlanTest.Layouts.PlanTest
{
public partial class GridPlan : LayoutsPageBase
{
TestEntities ent = new TestEntities();
protected void Page_Load(object sender, EventArgs e)
{
} protected void gdv_OnLoad(object sender, EventArgs e)
{
int weekCount = 5;
string startDate = "2013/7/26";
string[] weeks = GetDatequantumList(weekCount, startDate);
gdv.DataSource = GetDataTable(weeks);
if (!IsPostBack && !IsCallback)
{
PopulateColumns(weeks);
gdv.DataBind();
}
else
{
CreateTemplate(weeks);
}
} private object GetDataTable(string[] weeks)
{
string colNames = string.Empty;// "ID,";
DataTable table = ent.InfoList.ToDataTable();
for (int i = 0; i < weeks.Length; i++)
{
table.Columns.Add(weeks[i], typeof(string));
colNames += weeks[i] + ",";
}
colNames = colNames.TrimEnd(',');
hdl.Set("colNames", colNames);
foreach (DataRow row in table.Rows)
{
int id = Convert.ToInt32(row["ID"]);
List<Plan> plans = ent.Plan.Where(p => p.InfoList.ID == id).ToList();
for (int j = 0; j < weeks.Length; j++)
{
//字段的值保存id和value的对应关系
row[weeks[j]] = plans[j].Count + "|" + plans[j].ID;
}
}
return table;
} public void PopulateColumns(string[] weeks)
{
GridViewBandColumn bandColumn = new GridViewBandColumn();
bandColumn.Caption = "测试";
for (int i = 0; i < weeks.Length; i++)
{
GridViewDataTextColumn colItemTemplate = new GridViewDataTextColumn();
colItemTemplate.DataItemTemplate = new MyTextTemplate(); // Create a template
colItemTemplate.FieldName = weeks[i];
colItemTemplate.Caption = weeks[i];
bandColumn.Columns.Add(colItemTemplate);
}
gdv.Columns.Add(bandColumn);
} private void CreateTemplate(string[] weeks)
{
for (int i = 0; i < weeks.Length; i++)
{
((GridViewDataColumn)gdv.Columns[weeks[i]]).DataItemTemplate = new MyTextTemplate();
}
} protected void clb_OnCallback(object source, CallbackEventArgs e)
{
try
{
string[] newValues = e.Parameter.TrimEnd('|').Split('|');
foreach (string newValue in newValues)
{
int workload = Convert.ToInt32(newValue.Substring(0, newValue.IndexOf('&')));
int planID = Convert.ToInt32(newValue.Substring(newValue.IndexOf('&') + 1));
Plan plan = ent.Plan.Where(p => p.ID == planID).FirstOrDefault();
if (plan != null)
{
plan.Count = workload;
}
}
ent.SaveChanges();
e.Result = "1";
}
catch
{
e.Result = "0";
}
}
} class MyTextTemplate : ITemplate
{
public void InstantiateIn(Control container)
{
using (GridViewDataItemTemplateContainer gridContainer = (GridViewDataItemTemplateContainer)container)
{
string fieldValue = gridContainer.Grid.GetRowValuesByKeyValue(gridContainer.KeyValue, gridContainer.Column.FieldName).ToString();
ASPxTextBox txt = new ASPxTextBox();
txt.Width = 46;
txt.Text = fieldValue.Substring(0, fieldValue.IndexOf("|"));
txt.JSProperties["cpID"] = fieldValue.Substring(fieldValue.IndexOf("|") + 1);
txt.ClientInstanceName = "txt" + gridContainer.KeyValue.ToString() + gridContainer.Column.FieldName;
txt.DisplayFormatString = "F2";
container.Controls.Add(txt);
}
}
}
}
Above is almost full code what I did for test. It mainly used in the situation of making plans, which user can complete the plan of multiple work at one time.
All rights reserved
DevExpress Add ASPxGridView template columns at runtime的更多相关文章
- devexpress中ASPxGridView控件初始化赋值
写在ASPxGridView中OnCellEditorInitialize="ASPxGridView_progoods_CellEditorInitialize" 事件中: / ...
- DevExpress之ASPxGridView笔记(1)
1.设置Row(某列)输出格式,例如,在数字前加美元符.每3位以逗号隔开及设置小数点后两位: <dx:GridViewDataTextColumn FieldName="SHOUHUI ...
- Devexpress 使用经验 —— ASPxGridView命令行自定义按钮灵活使用
ASPX <dx:ASPxGridView ID="ASPxGridView1" runat="server" DataSourceID="Ob ...
- Devexpress 使用经验 —— ASPxGridView前后台交互写法推荐
这里的格式是仁者见仁智者见智,这篇随笔只是我在工作过程中总结出的阅读性高,对我来说效率较高的写法. ASPX: <dx:ASPxGridView ID="ASPxGridViewLin ...
- DB2 Add hidden Identity columns
An identity column contains a unique numeric value for each row in the table. DB2® can automatically ...
- [MODx] 1. Add Html5 template into the MODx
1. Connet MODx by SSH: Go to the MODx cloud; Find you current user and right click selet Edit Cloud; ...
- add some template for ec-final
二维rmq 离线 init O( n*n*logn*logn ) query O(1) http://www.cnblogs.com/kuangbin/p/3227420.html 求1-n有多少个 ...
- DevExpress的 ASPxGridview控件的自动配置效果
[淘宝小店:http://shop107919332.taobao.com ] 软件运行界面.是不是很漂亮? 这里是系统配置页面,可以随时根据需要配置每张表的每个字段的显示顺序,可见与否,只读与否,编 ...
- DevExpress控件使用系列--ASPxGridView+Popup+Tab
1.控件功能 列表控件展示数据.弹框控件执行编辑操作.Tab控件实现多标签编辑操官方说明 2.官方示例 2.1 ASPxGridView http ...
随机推荐
- php跨域
<?php header('Content-type:text/html; charset="utf-8"'); $url = 'http://10.32.41.194:80 ...
- Cocos2d-x学习笔记(八)精灵对象的创建
精灵类即是Sprite,它实际上就是一张二维图. 它首先直接继承了Node类,因此,它具有节点的特征,同时,它也直接继承了TextureProtocol类,因此,它也具有纹理的基本特征. 这里,有必要 ...
- C++ 在容器A中查找最后出现的容器B中的元素,并返回iterator(find_end)
#include <iostream> // cout #include <algorithm> // find_end #include <vector> // ...
- SQLServer中round函数
---SQL四舍五入问题1: SELECT CAST('123.456' as decimal) ---123 将会得到 123(小数点后面的将会被省略掉). ---如果希望得到小数点后面的两位.则需 ...
- python3.6 ImportWarning: can't resolve package from __spec__ or __package__, falling back on __name__ and __path__
Cython emulates Python 2-style implicit relative imports on Python 3 Cython的锅(也就是绝大多数下载安装的python)新的i ...
- resin中关于url rewrite来传递jsessionid的问题
最近两天在项目中碰到,一个很奇怪的问题.同一个账号多次切换登录时,会出现这个账号的信息在session中找不到,虽然可以登录成功,但是之后这个用户信息好像没有保存到session中一样,或者是被改变了 ...
- Java 类及其组成可使用的修饰符
2017-11-04 21:51:04 类: 默认,public(一个.java文件只能有一个public类),final,abstract 自己定义,public居多 不允许使用static,pri ...
- Java 集合-Collection接口和迭代器的实现
2017-10-30 00:30:48 Collection接口 Collection 层次结构 中的根接口.Collection 表示一组对象,这些对象也称为 collection 的元素.一些 c ...
- C#验证中文
C#验证中文的方式有很多种,下面列举了其中几种可供参考,还有正则表达式的验证这里没有写,后面有机会再补上. 方法一: private bool isChina(string msg) { string ...
- [Java学习] Java继承的概念与实现
继承是类与类之间的关系,是一个很简单很直观的概念,与现实世界中的继承(例如儿子继承父亲财产)类似. 继承可以理解为一个类从另一个类获取方法和属性的过程.如果类B继承于类A,那么B就拥有A的方法和属性. ...