DevExpress控件使用系列--ASPxGridView+Popup+Tab
列表控件展示数据、弹框控件执行编辑操作、Tab控件实现多标签编辑操官方说明
2、官方示例
http://documentation.devexpress.com/#AspNet/CustomDocument5823
3.1 aspx页面说明
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="DemoGridView.aspx.cs" Inherits="Demo_DemoGridView" %> <asp:Content ID="Content1" ContentPlaceHolderID="cphJs" runat="Server">
<script type="text/javascript">
var key = "Id";
function Menu_Click(s, e) {
if (e.item.name == "add") {
grid.AddNewRow();
}
} //自定义命令
function CustomButtonClick(s, e) {
var value = s.GetRowKey(e.visibleIndex);
AddCollection(key, value);
if (e.buttonID == "SetPasswordButton") { //如果点击的是【重置密码】链接,则打开
PopupSetPassword.Show();
}
}
function SetPasswordClick(s, e) {
if (true) {
PopupSetPassword.PerformCallback(txtPwd.GetText()); //触发后台事件,并传参数
}
else { alert("两次密码不一致!"); }
} //键值对,和服务器端通信
function AddCollection(key, value) {
if (HiddenField.Get(key) == null) {
HiddenField.Add(key, value);
}
else {
HiddenField.Set(key, value);
}
}
function PopupSetPassword_endCallback(s, e) {
PopupSetPassword.Hide();
Toast.Show(s.cp_retValue);
} //省市县
var lastCountry = null;
var lastCity = null;
function OnCountryChanged(cmbCountry) {
if (grid.GetEditor("CityCode").InCallback())
lastCountry = cmbCountry.GetValue().toString();
else {
lastCountry = cmbCountry.GetValue().toString(); //触发后台的grid_CellEditorInitialize事件,重新绑定省市县信息
grid.GetEditor("CityCode").PerformCallback(cmbCountry.GetValue().toString());
grid.GetEditor("TownCode").PerformCallback(lastCountry + "," + lastCity);
}
}
function OnCityChanged(cmbCity) {
//Returns a value that determines whether a callback request sent by a web control is being currently processed on the server side.
if (grid.GetEditor("TownCode").InCallback())
lastCity = cmbCity.GetValue().toString();
else {
//触发onchagne事件
grid.GetEditor("TownCode").PerformCallback(lastCountry + "," + cmbCity.GetValue().toString());
}
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="c1" runat="Server"> </asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="c2" runat="Server">
<dx:ASPxGridView runat="server" ID="grid" Width="100%" ClientInstanceName="grid"
KeyFieldName="Id" OnRowInserting="grid_RowInserting" OnRowDeleting="grid_RowDeleting"
OnRowUpdating="grid_RowUpdating" AutoGenerateColumns="False" OnHtmlEditFormCreated="grid_HtmlEditFormCreated"
OnCellEditorInitialize="grid_CellEditorInitialize">
<ClientSideEvents CustomButtonClick="CustomButtonClick" />
<Columns>
<dx:GridViewDataTextColumn FieldName="TrueName" Caption="真实姓名" VisibleIndex="">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="EnterpriseName" Caption="企业" VisibleIndex="">
<%--新增、编辑窗体不显示该列--%>
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataComboBoxColumn FieldName="UserTypeName" VisibleIndex="" Caption="用户类型">
<EditFormSettings Visible="False" />
</dx:GridViewDataComboBoxColumn>
<%--该列在列表窗体不显示--%>
<dx:GridViewDataTextColumn FieldName="Tel" VisibleIndex="" Caption="电话" Visible="false">
<EditFormSettings Visible="True" />
</dx:GridViewDataTextColumn>
<%--省市县联动--%>
<dx:GridViewDataComboBoxColumn FieldName="ProvinceCode" VisibleIndex="" Caption="省编码"
Visible="false">
<EditFormSettings Visible="True" />
<PropertiesComboBox>
<ClientSideEvents SelectedIndexChanged="function(s, e) { OnCountryChanged(s); }">
</ClientSideEvents>
</PropertiesComboBox>
</dx:GridViewDataComboBoxColumn>
<dx:GridViewDataComboBoxColumn FieldName="CityCode" VisibleIndex="" Caption="市编码"
Visible="false">
<EditFormSettings Visible="True" />
<PropertiesComboBox>
<ClientSideEvents SelectedIndexChanged="function(s, e) { OnCityChanged(s); }"></ClientSideEvents>
</PropertiesComboBox>
</dx:GridViewDataComboBoxColumn>
<dx:GridViewDataComboBoxColumn FieldName="TownCode" VisibleIndex="" Caption="县编码"
Visible="false">
<EditFormSettings Visible="True" />
</dx:GridViewDataComboBoxColumn>
<%--省市县联动--%>
<%--命令按钮--%>
<dx:GridViewCommandColumn VisibleIndex="" Caption="操作" Width="">
<EditButton Visible="true" Text="编辑">
</EditButton>
<DeleteButton Visible="true" Text="删除">
</DeleteButton>
<CellStyle HorizontalAlign="Center">
</CellStyle>
</dx:GridViewCommandColumn>
<dx:GridViewCommandColumn Caption="重置密码" VisibleIndex="" AllowDragDrop="False">
<CustomButtons>
<dx:GridViewCommandColumnCustomButton ID="SetPasswordButton" Text="重置密码">
</dx:GridViewCommandColumnCustomButton>
</CustomButtons>
</dx:GridViewCommandColumn>
</Columns>
<GroupSummary>
<dx:ASPxSummaryItem FieldName="EnterpriseCount" DisplayFormat="{0}数量" SummaryType="Count" />
</GroupSummary>
<Templates>
<%--新增、修改Tab控件--%>
<EditForm>
<div style="padding: 4px 4px 3px 4px">
<dx:ASPxPageControl runat="server" ID="pageControlUser" Width="100%">
<TabPages>
<dx:TabPage Text=" 基本信息" Visible="true">
<ContentCollection>
<dx:ContentControl ID="ContentControl1" runat="server">
<dx:ASPxGridViewTemplateReplacement ID="Editors" ReplacementType="EditFormEditors"
runat="server"></dx:ASPxGridViewTemplateReplacement>
</dx:ContentControl>
</ContentCollection>
</dx:TabPage>
<dx:TabPage Text="类型" Visible="true">
<ContentCollection>
<dx:ContentControl ID="ContentControl2" runat="server">
<dx:ASPxTreeList ID="OrgUnitTree" runat="server" AutoGenerateColumns="False" Width="100%"
KeyFieldName="OrgUnitId" ParentFieldName="ParentId" ClientInstanceName="OrgUnitTree">
<Columns>
<dx:TreeListDataColumn FieldName="Name" Caption="名称">
<CellStyle Wrap="True">
</CellStyle>
</dx:TreeListDataColumn>
<dx:TreeListComboBoxColumn FieldName="TypeName" Caption="类型名称">
<EditFormSettings Visible="False" />
</dx:TreeListComboBoxColumn>
<dx:TreeListDataColumn FieldName="LinkMan" Caption="联系人" />
</Columns>
<SettingsBehavior AllowFocusedNode="True" AllowDragDrop="false" ProcessSelectionChangedOnServer="false" />
<Settings VerticalScrollBarMode="Auto" ShowTreeLines="true" GridLines="Horizontal" />
<SettingsPager PageSize="" PageSizeItemSettings-Caption="每页显示:" AlwaysShowPager="True"
CurrentPageNumberFormat="{0}" Mode="ShowPager">
<Summary AllPagesText="总页数: {0} - {1} (共有 {2} 条数据)" Text="总页数: {0} - {1} (共有 {2} 条数据)" />
</SettingsPager>
</dx:ASPxTreeList>
</dx:ContentControl>
</ContentCollection>
</dx:TabPage>
</TabPages>
</dx:ASPxPageControl>
</div>
<div style="text-align: right; padding: 2px 2px 2px 2px">
<dx:ASPxGridViewTemplateReplacement ID="UpdateButton" ReplacementType="EditFormUpdateButton"
runat="server"></dx:ASPxGridViewTemplateReplacement>
<dx:ASPxGridViewTemplateReplacement ID="CancelButton" ReplacementType="EditFormCancelButton"
runat="server"></dx:ASPxGridViewTemplateReplacement>
</div>
</EditForm>
</Templates>
<SettingsPopup EditForm-Modal="true" EditForm-HorizontalAlign="WindowCenter" CustomizationWindow-HorizontalAlign="WindowCenter"
CustomizationWindow-VerticalAlign="WindowCenter">
<EditForm Width="550px" Height="400px" HorizontalAlign="Center" Modal="True"></EditForm>
</SettingsPopup>
<Settings ShowGroupPanel="true" />
<SettingsEditing Mode="PopupEditForm" />
</dx:ASPxGridView>
<dx:ASPxPopupControl ID="PopupSetPassword" runat="server" CloseAction="CloseButton"
Modal="True" PopupVerticalAlign="WindowCenter" PopupHorizontalAlign="WindowCenter"
AllowDragging="True" ShowFooter="True" Width="350px" Height="130px" HeaderText="重置密码"
ClientInstanceName="PopupSetPassword" OnWindowCallback="PopupSetPassword_WindowCallback">
<ClientSideEvents EndCallback="PopupSetPassword_endCallback" />
<ContentCollection>
<dx:PopupControlContentControl ID="PopupControlContentControl2" runat="server">
<table class="dxgvEditFormTable_Glass">
<tr>
<td style="white-space: nowrap">
新密码:<dx:ASPxHiddenField runat="server" ID="HiddenField" ClientInstanceName="HiddenField">
</dx:ASPxHiddenField>
</td>
<td class="dxgvEditFormCell_Glass">
<dx:ASPxTextBox ID="txtPwd" Password="true" runat="server" Width="" ClientInstanceName="txtPwd">
</dx:ASPxTextBox>
</td>
</tr>
</table>
</dx:PopupControlContentControl>
</ContentCollection>
<FooterTemplate>
<div style="float: right; margin: 3px;">
<dx:ASPxButton ID="RolesListButton" runat="server" Text=" 确认 " AutoPostBack="False"
ClientSideEvents-Click="SetPasswordClick">
</dx:ASPxButton>
</div>
</FooterTemplate>
</dx:ASPxPopupControl>
</asp:Content>
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web.ASPxGridView;
using DevExpress.Web.ASPxTreeList;
using PanPass.YDYX.Model;
using PanPass.YDYX.BLL;
using DevExpress.Web.ASPxEditors;
using DevExpress.Web.ASPxTabControl;
using DevExpress.Web.ASPxClasses;
using PanPass.Commons; public partial class Demo_DemoGridView : System.Web.UI.Page
{
protected void AddError(Dictionary<GridViewColumn, string> errors, GridViewColumn column, string errorText)
{
if (errors.ContainsKey(column)) return;
errors[column] = errorText;
} protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{ }
} //新增修改验证
public override void ValidateRow(DevExpress.Web.Data.ASPxDataValidationEventArgs e)
{ if (e.NewValues["TrueName"] == null)
{
AddError(e.Errors, grid.Columns["TrueName"], "真实姓名不能为空.");
} if (e.NewValues["LoginName"] != null && e.NewValues["LoginName"].ToString().Trim().Length < )
{
AddError(e.Errors, grid.Columns["LoginName"], "登录名长度不能小于3.");
} if (grid.IsEditing && grid.IsNewRowEditing) //新增验证
{ }
else if (!grid.IsNewRowEditing) //修改验证
{ } if (string.IsNullOrEmpty(e.RowError) && e.Errors.Count > ) e.RowError = "请改正错误."; } //进入新增、修改页面时初始化或获取数据
protected void grid_CellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e)
{ if (grid.IsEditing) //编辑
{ }
else //新增
{ } if (grid.IsEditing && e.Column.FieldName == "ProvinceCode")
{
ASPxComboBox combo = e.Editor as ASPxComboBox;
//FillProvinceData(combo); 绑定省份信息
}
if (grid.IsEditing && e.Column.FieldName == "CityCode")
{
ASPxComboBox combo = e.Editor as ASPxComboBox;
object val = grid.GetRowValuesByKeyValue(e.KeyValue, "ProvinceCode");
//BindCbCityByProvince(combo, val); 绑定城市信息
}
if (grid.IsEditing && e.Column.FieldName == "TownCode")
{
ASPxComboBox combo = e.Editor as ASPxComboBox;
object ProvinceCode = grid.GetRowValuesByKeyValue(e.KeyValue, "ProvinceCode");
object CityCode = grid.GetRowValuesByKeyValue(e.KeyValue, "CityCode");
//BindCountyByCity(combo, ProvinceCode, CityCode); 绑定县级信息
}
} void grid_CustomButtonCallback(object sender, ASPxGridViewCustomButtonCallbackEventArgs e)
{
if (e.ButtonID == "DeleteButtonID")
{ }
} //绑定数据
public void bindData()
{ } #region grid事件
//初始化Page控件树
protected void grid_HtmlEditFormCreated(object sender, ASPxGridViewEditFormEventArgs e)
{ } protected void grid_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
{ grid.CancelEdit();
e.Cancel = true;
bindData();
//调用js方法
//String js = "gv.PerformCallback();";
//ScriptManager.RegisterStartupScript(Page, this.GetType(), "", js, true);
}
protected void grid_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e)
{
grid.CancelEdit();
e.Cancel = true;
bindData();
}
protected void grid_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
{
grid.CancelEdit();
e.Cancel = true;
bindData();
}
#endregion protected void PopupSetPassword_WindowCallback(object source, DevExpress.Web.ASPxPopupControl.PopupWindowCallbackArgs e)
{
int userid = HiddenField.Get("UserId").ToInt().Value;
//e.Parameter; 获取传递的参数
//userid获取在CustomButtonClick添加的隐藏内容 PopupSetPassword.JSProperties["cp_retValue"] = "密码修改成功"; } }
Attachment List
DevExpress控件使用系列--ASPxGridView+Popup+Tab的更多相关文章
- DevExpress控件使用系列--ASPxUploadControl(图片上传及预览)
1.控件功能 列表控件展示数据.弹框控件执行编辑操作.Tab控件实现多标签编辑操官方说明 2.官方示例 2.1 ASPxImage http: ...
- DevExpress控件使用系列--ASPxTreeList
控件功能 结合列表控件及树控件的优点,在列表控件中实现类型树的多层级操作 官方说明 http://documentation.devexpress.com/#AspNet/clsDevExpres ...
- DevExpress控件的GridControl控件小结
DevExpress控件的GridControl控件小结 (由于开始使用DevExpress控件了,所以要点滴的记录一下) 1.DevExpress控件组中的GridControl控件不能使横向滚动条 ...
- DevExpress控件学习总结(转)
DevExpress控件学习总结 1.Navigation & Layout 1.1 Bar Manager 如果想在窗体或用户控件(user control)上添加工具条(bars)或弹 ...
- DevExpress控件的一些快捷操作
用的DevExpress控件时,有一些操作并不太方便,根据我自己需要的封装了一些控件的事件,调用的时候直接绑定控件的事件就可以了 例如: this.ComboBoxEdit.KeyDown += Ct ...
- DevExpress控件库 开发使用经验总结3 制作项目安装包
2015-01-27 使用DevExpress控件包开发C/S项目完成后,部署前需要制作本地安装包.本文还是使用“SetupFactory”安装工厂来制作安装包.在以前的系列文章中详细介绍过该工具的使 ...
- DevExpress控件库 开发使用经验总结1 DevExpress简介、安装、使用
2015-01-24 最近公司开发的WinForm客户端图书行业ERP管理系统,界面端采用了DevExpress控件库.界面效果非常绚丽,类似于Office2007.2010的界面风格. 其中的控件功 ...
- DevExpress控件使用之多重坐标图形的绘制 z
有时候,基于对一些年份.月份的统计,需要集成多个数值指标进行分析,因此就需要把多种数据放到一个图形里面展现,也成为多重坐标轴,多重坐标轴可以是多个X轴,也可以是Y轴,它们的处理方式类似.本文通过一个例 ...
- DevExpress控件与VS和.NET各个版本的支持情况
如下图所示,绿色Yes代表支持,红色No代表不支持.对于有些人觉得装了dev后,vs工具箱没有,一般都是以下两大问题: 1.要么你的Dev的版本不支持你当前的VS版本,没有很正常. 2.要么你的项目的 ...
随机推荐
- 怎么手写Ajax实现异步刷新
所谓的异步刷新,就是不刷新整个网页进行更新数据. 只有通过js才能实现Ajax,进而实行异步刷新 表单提交数据和Ajax提交数据的区别:表单提交是提交的整个页面中的数据,提交数据之后会抛弃之前的页面( ...
- SQL取某个字段最大(小)数值及其相应行的其他字段值的句语
如下表Z 中,取 字段a 最大的那行 字段a 字段a 字段cSP000016964 5 20SP000016964 7 30SP000016964 1 15SP0000177 ...
- VSS汉化后出现问题及解决方法
1.vss汉化后在获取项目时不递归获取? 解决方法:工具-->选项-->常规-->勾选 项目递归时有效(R) 2.查看差异,可视化窗口未出现分隔? 解决方法:差异选项-->格式 ...
- JQuery Pagination 分页插件 增加了首页尾页以及跳转功能
JQuery分页插件 挺好用的 但是官方是没有提供首页尾页以及跳转功能 我觉得这个功能可以有,于是就改进了一下 一个js一个css从连接里面下 链接:http://pan.baidu.com/s/1n ...
- CentOS6.4下使用默认的PDF文档阅读器出现乱码的解决方案
方法一:修改/etc/fonts/conf.d/49-sansserif.conf文件,如下: 1: <?xml version="1.0"?> 2: <!DOC ...
- 内核 current宏解析
Technorati 标签: current thread_info 在内核中,可以通过current宏来获得当前执行进程的task_struct指针.现在来简要分析以下: 最原始 ...
- UITableView学习笔记
//非原创 看TableView的资料其实已经蛮久了,一直想写点儿东西,却总是因为各种原因拖延,今天晚上有时间静下心来记录一些最近学习的TableView的知识.下面进入正题,UITableView堪 ...
- VirtrualBox 搭建本地lamp环境
1.VirtrualBox安装Centos6.8 minimal VirtrualBox新建个虚拟机配置好内存以及硬盘大小,安装即可: 网络方式是 NAT(默认)和桥接方式来实现,最好在安装前设置好, ...
- ECSHOP的订单状态在数据库中的表现(order_status, shipping_status, pay_status)
echop的订单状态都是在ecs_order_info表中的字段里. 订单状态 未确认 取消 确认 已付款 配货中 已发货 已收货 退货 order_status 0 2 1 1 1 5 5 4 sh ...
- C# 顺序表操作
虽然.NET已经是现实了Reverse(),但是学习算法有必要知道其是怎么实现的: private static void ReverseArray(int[] array) { int temp; ...