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 ...
随机推荐
- BZOJ 4416 【SHOI2013】 阶乘字符串
题目链接:阶乘字符串 又是一道不会做的题……看了题解后我被吓傻了…… 首先我们可以有一个显然的\(O(2^nn)\)的做法.我们先预处理出\(g_{i,j}\)表示字符串中\(i\)号位置开始第一个\ ...
- python学习——大文件分割与合并
在平常的生活中,我们会遇到下面这样的情况: 你下载了一个比较大型的游戏(假设有10G),现在想跟你的同学一起玩,你需要把这个游戏拷贝给他. 然后现在有一个问题是文件太大(我们不考虑你有移动硬盘什么的情 ...
- python 集合删除元素
#Create a new set num_set = , , , , , ]) #Discard number num_set.discard() print(num_set)
- linux c/c++ 删除文件
linux c/c++ 删除文件 #include <stdio.h> int FileRemove(const char* fname) { return remove(fname); ...
- Codeforces 197D - Infinite Maze
197D - Infinite Maze 思路:bfs,如果一个点被搜到第二次,那么就是符合要求的. 用vis[i][j].x,vis[i][j].y表示i,j(i,j是取模过后的值)这个点第一次被搜 ...
- C++STL3--queue
C++STL3--queue 一.心得 STL的这些东西用法都差不多 二.介绍 queue数据结构中的队列 priority_queue优先队列,插入进去的元素都会从大到小排好序 PS:在priori ...
- 显示Unicode 字节的对应字符的小技巧
在一段smali代码里看到这样的代码 const-string v0, "\u7528\u6237\u9a8c\u8bc1\u8fc7\u671f\uff0c\u8bf7\u91cd\u65 ...
- LeetCode--122--卖卖股票的最佳时机II
问题描述: 给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格. 设计一个算法来计算你所能获取的最大利润.你可以尽可能地完成更多的交易(多次买卖一支股票). 注意:你不能同时参与多笔交易( ...
- codeforces 966c//Big Secret// Codeforces Round #477 (Div. 1)
题意:一个数组,重新打乱后前缀异或和递增.问这样的排列. 将所有元素按照二进制最高位分组.每次选当前前缀和sum的二进制最低的0位,再从分组中挑一个作为答案.先放首1在较低位的再放首1在较高位的总是可 ...
- Ciel the Commander CodeForces - 321C (树, 思维)
链接 大意: 给定n结点树, 求构造一种染色方案, 使得每个点颜色在[A,Z], 且端点同色的链中至少存在一点颜色大于端点 (A为最大颜色) 直接点分治即可, 因为最坏可以涂$2^{26}-1$个节点 ...