DevExpress ASP.NET 使用经验谈(8)-ASPxGridView自定义列和基本事件

为演示本节示例,我们在原来Users表增加【性别Gender】、【兴趣爱好Hobbies】,【CreateTime创建时间】,【ModifyTime】修改时间这4个字段,

ALTER TABLE [dbo].[Users] add [Gender] varchar(10) NULL
GO
ALTER TABLE [dbo].[Users] add [Hobbies] varchar(50) NULL
GO
ALTER TABLE [dbo].[Users] add [CreateTime] datetime NULL
GO
ALTER TABLE [dbo].[Users] add [ModifyTime] datetime NULL

完成建表语句如下:

CREATE TABLE [dbo].[Users] (
    [UserID] int IDENTITY(1, 1) NOT NULL,
    [UserName] nvarchar(50) NULL,
    [FirstName] nvarchar(50) NULL,
    [LastName] nvarchar(50) NULL,
    [MiddleName] nvarchar(50) NULL,
    [EmailID] nvarchar(50) NULL,
    [Gender] varchar(10) NULL,
    [Hobbies] varchar(50) NULL,
    [ModifyTime] datetime NULL,
    [CreateTime] datetime NULL,
    CONSTRAINT [PK_Users] PRIMARY KEY ([UserID])
)

【性别】:我们选择ASPxGridView的GridViewDataComboBoxColumn列类型,通过如下代码实现下拉选择性别“男”和“女”。

 <dx:GridViewDataComboBoxColumn FieldName="Gender" VisibleIndex="6" Caption="性别" Width="80px">
                        <EditFormSettings VisibleIndex="4" Visible="True" Caption="性别" />
                        <CellStyle HorizontalAlign="Center" />
                        <HeaderStyle HorizontalAlign="Center" />
                        <PropertiesComboBox>
                            <Items>
                                <dx:ListEditItem Text="男" Value="男" />
                                <dx:ListEditItem Text="女" Value="女" />
                            </Items>
                        </PropertiesComboBox>
</dx:GridViewDataComboBoxColumn>

【兴趣爱好】:通过编辑模板EditItemTemplate,建立自定义的兴趣爱好CheckBox选项的模板列。

 <dx:GridViewDataTextColumn FieldName="Hobbies" VisibleIndex="7" Caption="兴趣爱好" Width="100px">
                        <EditFormSettings VisibleIndex="5" Visible="True" Caption="兴趣爱好" />
                        <CellStyle HorizontalAlign="Center" />
                        <HeaderStyle HorizontalAlign="Center" />
                        <EditItemTemplate>
                            <table border="0">
                                <tr>
                                    <td>
                                        <dx:ASPxCheckBox ID="ASPxCheckBox_H1" runat="server" ClientInstanceName="cb_hob1" Text="阅读" Layout="Flow" OnInit="ASPxCheckBox_Hobbies_Init">
                                        </dx:ASPxCheckBox>
                                    </td>
                                    <td> </td>
                                    <td>
                                        <dx:ASPxCheckBox ID="ASPxCheckBox_H2" ClientInstanceName="cb_hob2" runat="server" Text="思考" Layout="Flow" OnInit="ASPxCheckBox_Hobbies_Init">
                                        </dx:ASPxCheckBox>
                                    </td>
                                    <td> </td>
                                    <td>
                                        <dx:ASPxCheckBox ID="ASPxCheckBox_H3" runat="server" ClientInstanceName="cb_hob3" Text="运动" Layout="Flow" OnInit="ASPxCheckBox_Hobbies_Init">
                                        </dx:ASPxCheckBox>
                                    </td>
                                    <td> </td>
                                    <td>
                                        <dx:ASPxCheckBox ID="ASPxCheckBox_H4" runat="server" ClientInstanceName="cb_hob4" Text="社交" Layout="Flow" OnInit="ASPxCheckBox_Hobbies_Init">
                                        </dx:ASPxCheckBox>
                                    </td>
                                </tr>
                            </table>
                        </EditItemTemplate>
</dx:GridViewDataTextColumn>

【 创建时间】与【修改时间】在界面上均不显示,分别记录每条数据的创建时间和最后一次修改时间。

 <dx:GridViewDataDateColumn FieldName="CreateTime" VisibleIndex="7" Caption="创建时间" Width="100px" Visible="false">
                        <EditFormSettings VisibleIndex="5" Visible="False" Caption="创建时间" />
                        <CellStyle HorizontalAlign="Center" />
                        <HeaderStyle HorizontalAlign="Center" />
                    </dx:GridViewDataDateColumn>
<dx:GridViewDataDateColumn FieldName="ModifyTime" VisibleIndex="7" Caption="修改时间" Width="100px" Visible="false">
                        <EditFormSettings VisibleIndex="5" Visible="True" Caption="修改时间" />
                        <CellStyle HorizontalAlign="Center" />
                        <HeaderStyle HorizontalAlign="Center" />
</dx:GridViewDataDateColumn>

关于这4个字段的后台赋值,我们暂先放一边,来看一下,目前编辑界面的效果。

图一 添加字段后的编辑页

【性别】字段,可以直接下拉选择并保存,但是【兴趣爱好】选项选取后保存无效,【创建时间】,【修改时间】因为并未开放编辑,且后台并未赋值,

所以仍为空值。那么如何才能保存这三个字段呢?

这里我们就要利用ASPxGridView的OnRowInserting事件、OnRowUpdating事件来执行赋值和保存。

后台OnRowInserting事件代码如下:

 protected void ASPxGridView1_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
    {
        //在RowInserting时,将当前时间赋值给“创建时间列”CreateTime赋值
        e.NewValues["CreateTime"] = DateTime.Now;

        GridViewDataColumn columnHobbies = ASPxGridView1.Columns["Hobbies"] as GridViewDataColumn; //取出GridView的Column
        //通过ASPxGridView1.FindEditRowCellTemplateControl找出自定义的CheckBox
        ASPxCheckBox cbH1 = (ASPxGridView1.FindEditRowCellTemplateControl(columnHobbies, "ASPxCheckBox_H1") as ASPxCheckBox);
        ASPxCheckBox cbH2 = (ASPxGridView1.FindEditRowCellTemplateControl(columnHobbies, "ASPxCheckBox_H2") as ASPxCheckBox);
        ASPxCheckBox cbH3 = (ASPxGridView1.FindEditRowCellTemplateControl(columnHobbies, "ASPxCheckBox_H3") as ASPxCheckBox);
        ASPxCheckBox cbH4 = (ASPxGridView1.FindEditRowCellTemplateControl(columnHobbies, "ASPxCheckBox_H4") as ASPxCheckBox);

        ArrayList listHobbies = new ArrayList();
        if (cbH1.Checked == true)
        {
            listHobbies.Add(cbH1.Text);
        }
        if (cbH2.Checked == true)
        {
            listHobbies.Add(cbH2.Text);
        }
        if (cbH3.Checked == true)
        {
            listHobbies.Add(cbH3.Text);
        }
        if (cbH4.Checked == true)
        {
            listHobbies.Add(cbH4.Text);
        }
        //通过 e.NewValues["Hobbies"]赋值
        e.NewValues["Hobbies"] = string.Join(",", listHobbies.ToArray());
    }

我们可以通过e.NewValues["列名"]赋值来存取数据,通过ASPxGridView1.FindEditRowCellTemplateControl方法,可以找到模板列中的

自定义控件。

同理,后台RowUpdating事件如下:

 protected void ASPxGridView1_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
    {
        //在RowUpdating时,将当前时间赋值给“创建时间列”ModifyTime赋值
        e.NewValues["ModifyTime"] = DateTime.Now;

        GridViewDataColumn columnHobbies = ASPxGridView1.Columns["Hobbies"] as GridViewDataColumn;//取出GridView的Column
        //通过ASPxGridView1.FindEditRowCellTemplateControl找出自定义的CheckBox
        ASPxCheckBox cbH1 = (ASPxGridView1.FindEditRowCellTemplateControl(columnHobbies, "ASPxCheckBox_H1") as ASPxCheckBox);
        ASPxCheckBox cbH2 = (ASPxGridView1.FindEditRowCellTemplateControl(columnHobbies, "ASPxCheckBox_H2") as ASPxCheckBox);
        ASPxCheckBox cbH3 = (ASPxGridView1.FindEditRowCellTemplateControl(columnHobbies, "ASPxCheckBox_H3") as ASPxCheckBox);
        ASPxCheckBox cbH4 = (ASPxGridView1.FindEditRowCellTemplateControl(columnHobbies, "ASPxCheckBox_H4") as ASPxCheckBox);

        ArrayList listHobbies = new ArrayList();
        if (cbH1.Checked == true)
        {
            listHobbies.Add(cbH1.Text);
        }
        if (cbH2.Checked == true)
        {
            listHobbies.Add(cbH2.Text);
        }
        if (cbH3.Checked == true)
        {
            listHobbies.Add(cbH3.Text);
        }
        if (cbH4.Checked == true)
        {
            listHobbies.Add(cbH4.Text);
        }
        //通过 e.NewValues["Hobbies"]赋值
        e.NewValues["Hobbies"] = string.Join(",", listHobbies.ToArray());
    }

通过上面代码,我们已经能将【兴趣爱好】、【创建时间】、【修改时间】的数据保存到数据库,但是再次编辑时,【兴趣爱好】列数据并未绑定控件,

这时,就需要用到ASPxCheckBox控件的OnInit事件。

 <dx:ASPxCheckBox ID="ASPxCheckBox_H2" ClientInstanceName="cb_hob2" runat="server" Text="思考" Layout="Flow" OnInit="ASPxCheckBox_Hobbies_Init">
 </dx:ASPxCheckBox>

ASPxCheckBox_Hobbies_Init事件代码如下:

    protected void ASPxCheckBox_Hobbies_Init(object sender, EventArgs e)
    {
        ASPxCheckBox cblHb = sender as ASPxCheckBox;
        GridViewEditItemTemplateContainer container = cblHb.NamingContainer as GridViewEditItemTemplateContainer;
        string strHobbies = string.Empty;
        if (DataBinder.Eval(container.DataItem, "Hobbies") != null)
            strHobbies = DataBinder.Eval(container.DataItem, "Hobbies").ToString().Trim();

        if (strHobbies.Contains(cblHb.Text))
        {
            cblHb.Checked = true;
        }
    }

此时,我们新增一条数据,录入信息如下,点击保存,再次点击编辑图标打开编辑界面,已经显示【兴趣爱好】列的选择状态数据绑定,因为是

新增数据,所以【修改时间】为空。

图二 增加后台取值赋值代码,执行新增并保存后的界面

再次编辑,修改【兴趣爱好】选项,取消“运动“选项,增加”思考“选项,再保存,这时【修改时间】更新。

图三 再执行编辑并保存后的界面

最后贴出完整代码:

1、前台ASPX页面代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="DevExpress.Xpo.v12.2.Web, Version=12.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Xpo" TagPrefix="dx" %>

<%@ Register Assembly="DevExpress.Web.v12.2, Version=12.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dx" %>

<%@ Register Assembly="DevExpress.Web.v12.2, Version=12.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxEditors" 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>
            <p>
                <h1>ASPxGridView自定义列和事件</h1>
            </p>
            <dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False"
                OnRowInserting="ASPxGridView1_RowInserting"
                OnRowUpdating="ASPxGridView1_RowUpdating"
                DataSourceID="XpoDataSource1" KeyFieldName="UserID" Theme="Aqua">
                <Columns>
                    <dx:GridViewCommandColumn VisibleIndex="0" ButtonType="Image" Width="80px">
                        <EditButton Visible="true">
                            <Image ToolTip="编辑" Url="Assets/images/edit.png"></Image>
                        </EditButton>
                        <NewButton Visible="true">
                            <Image ToolTip="新增" Url="Assets/images/new.png"></Image>
                        </NewButton>
                        <DeleteButton Visible="true">
                            <Image ToolTip="删除" Url="Assets/images/delete.png"></Image>
                        </DeleteButton>
                        <UpdateButton Visible="true">
                            <Image ToolTip="保存" Url="Assets/images/save.gif"></Image>
                        </UpdateButton>
                        <CancelButton Visible="true">
                            <Image ToolTip="取消" Url="Assets/images/cancel.gif"></Image>
                        </CancelButton>
                    </dx:GridViewCommandColumn>
                    <dx:GridViewDataTextColumn FieldName="UserID" ReadOnly="True" VisibleIndex="1" Visible="false">
                    </dx:GridViewDataTextColumn>
                    <dx:GridViewDataTextColumn FieldName="UserName" VisibleIndex="2" Caption="用户姓名" >
                        <EditFormSettings VisibleIndex="2" Visible="True" Caption="用户姓名" />
                    </dx:GridViewDataTextColumn>
                    <dx:GridViewDataTextColumn FieldName="FirstName" VisibleIndex="3" Caption="名" Width="80px">
                        <EditFormSettings VisibleIndex="3" Visible="True" Caption="名" />
                        <CellStyle HorizontalAlign="Center" />
                        <HeaderStyle HorizontalAlign="Center" />
                    </dx:GridViewDataTextColumn>
                    <dx:GridViewDataTextColumn FieldName="LastName" VisibleIndex="4" Caption="姓" Width="80px">
                        <EditFormSettings VisibleIndex="4" Visible="True" Caption="姓" />
                        <CellStyle HorizontalAlign="Center" />
                        <HeaderStyle HorizontalAlign="Center" />
                    </dx:GridViewDataTextColumn>
                    <dx:GridViewDataTextColumn FieldName="MiddleName" VisibleIndex="5" Caption="教名" Width="100px">
                        <EditFormSettings VisibleIndex="5" Visible="False" Caption="教名" />
                        <CellStyle HorizontalAlign="Center" />
                        <HeaderStyle HorizontalAlign="Center" />
                    </dx:GridViewDataTextColumn>
                    <dx:GridViewDataComboBoxColumn FieldName="Gender" VisibleIndex="6" Caption="性别" Width="80px">
                        <EditFormSettings VisibleIndex="4" Visible="True" Caption="性别" />
                        <CellStyle HorizontalAlign="Center" />
                        <HeaderStyle HorizontalAlign="Center" />
                        <PropertiesComboBox>
                            <Items>
                                <dx:ListEditItem Text="男" Value="男" />
                                <dx:ListEditItem Text="女" Value="女" />
                            </Items>
                        </PropertiesComboBox>
                    </dx:GridViewDataComboBoxColumn>
                    <dx:GridViewDataTextColumn FieldName="Hobbies" VisibleIndex="7" Caption="兴趣爱好" Width="100px">
                        <EditFormSettings VisibleIndex="5" Visible="True" Caption="兴趣爱好" />
                        <CellStyle HorizontalAlign="Center" />
                        <HeaderStyle HorizontalAlign="Center" />
                        <EditItemTemplate>
                            <table border="0">
                                <tr>
                                    <td>
                                        <dx:ASPxCheckBox ID="ASPxCheckBox_H1" runat="server" ClientInstanceName="cb_hob1" Text="阅读" Layout="Flow" OnInit="ASPxCheckBox_Hobbies_Init">
                                        </dx:ASPxCheckBox>
                                    </td>
                                    <td> </td>
                                    <td>
                                        <dx:ASPxCheckBox ID="ASPxCheckBox_H2" ClientInstanceName="cb_hob2" runat="server" Text="思考" Layout="Flow" OnInit="ASPxCheckBox_Hobbies_Init">
                                        </dx:ASPxCheckBox>
                                    </td>
                                    <td> </td>
                                    <td>
                                        <dx:ASPxCheckBox ID="ASPxCheckBox_H3" runat="server" ClientInstanceName="cb_hob3" Text="运动" Layout="Flow" OnInit="ASPxCheckBox_Hobbies_Init">
                                        </dx:ASPxCheckBox>
                                    </td>
                                    <td> </td>
                                    <td>
                                        <dx:ASPxCheckBox ID="ASPxCheckBox_H4" runat="server" ClientInstanceName="cb_hob4" Text="社交" Layout="Flow" OnInit="ASPxCheckBox_Hobbies_Init">
                                        </dx:ASPxCheckBox>
                                    </td>
                                </tr>
                            </table>
                        </EditItemTemplate>
                    </dx:GridViewDataTextColumn>
                    <dx:GridViewDataTextColumn FieldName="EmailID" VisibleIndex="6" Caption="邮箱" Width="200px">
                        <EditFormSettings VisibleIndex="6" Visible="True" Caption="邮箱" ColumnSpan="2" />
                    </dx:GridViewDataTextColumn>
                    <dx:GridViewDataDateColumn FieldName="CreateTime" VisibleIndex="7" Caption="创建时间" Width="100px" >
                        <EditFormSettings VisibleIndex="5" Visible="False" Caption="创建时间" />
                        <CellStyle HorizontalAlign="Center" />
                        <HeaderStyle HorizontalAlign="Center" />
                    </dx:GridViewDataDateColumn>
                    <dx:GridViewDataDateColumn FieldName="ModifyTime" VisibleIndex="7" Caption="修改时间" Width="100px" >
                        <EditFormSettings VisibleIndex="5" Visible="False" Caption="修改时间" />
                        <CellStyle HorizontalAlign="Center" />
                        <HeaderStyle HorizontalAlign="Center" />
                    </dx:GridViewDataDateColumn>
                </Columns>
                <SettingsBehavior ConfirmDelete="true" AllowFocusedRow="true" AllowSelectSingleRowOnly="true" AllowSelectByRowClick="true" />
                <SettingsEditing EditFormColumnCount="2" />
                <Settings ShowFooter="True" />
                <SettingsText EmptyDataRow="无记录" ConfirmDelete="确定删除吗?" />
                <SettingsPager Mode="ShowPager" PageSize="3" />
            </dx:ASPxGridView>
        </div>
        <dx:XpoDataSource ID="XpoDataSource1" runat="server" TypeName="XPOModel.DemoDB.Users"></dx:XpoDataSource>
    </form>
</body>
</html>

2、后台代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using DevExpress.Xpo;
using DevExpress.Xpo.DB;
using DevExpress.Web.ASPxGridView;
using DevExpress.Web.ASPxEditors;
using System.Collections;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Init(object sender, EventArgs e)
    {
        string provider = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;//获取数据库连接
        IDataLayer datalayer = new SimpleDataLayer(XpoDefault.GetConnectionProvider(provider, AutoCreateOption.DatabaseAndSchema));//建立数据层XPO独有的
        DevExpress.Xpo.Session session = new DevExpress.Xpo.Session(datalayer); //将数据层和会话绑定
        XpoDataSource1.Session = session;
    }

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void ASPxCheckBox_Hobbies_Init(object sender, EventArgs e)
    {
        ASPxCheckBox cblHb = sender as ASPxCheckBox;
        GridViewEditItemTemplateContainer container = cblHb.NamingContainer as GridViewEditItemTemplateContainer;
        string strHobbies = string.Empty;
        if (DataBinder.Eval(container.DataItem, "Hobbies") != null)
            strHobbies = DataBinder.Eval(container.DataItem, "Hobbies").ToString().Trim();

        if (strHobbies.Contains(cblHb.Text))
        {
            cblHb.Checked = true;
        }
    }

    protected void ASPxGridView1_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
    {
        //在RowInserting时,将当前时间赋值给“创建时间列”CreateTime赋值
        e.NewValues["CreateTime"] = DateTime.Now;

        GridViewDataColumn columnHobbies = ASPxGridView1.Columns["Hobbies"] as GridViewDataColumn; //取出GridView的Column
        //通过ASPxGridView1.FindEditRowCellTemplateControl找出自定义的CheckBox
        ASPxCheckBox cbH1 = (ASPxGridView1.FindEditRowCellTemplateControl(columnHobbies, "ASPxCheckBox_H1") as ASPxCheckBox);
        ASPxCheckBox cbH2 = (ASPxGridView1.FindEditRowCellTemplateControl(columnHobbies, "ASPxCheckBox_H2") as ASPxCheckBox);
        ASPxCheckBox cbH3 = (ASPxGridView1.FindEditRowCellTemplateControl(columnHobbies, "ASPxCheckBox_H3") as ASPxCheckBox);
        ASPxCheckBox cbH4 = (ASPxGridView1.FindEditRowCellTemplateControl(columnHobbies, "ASPxCheckBox_H4") as ASPxCheckBox);

        ArrayList listHobbies = new ArrayList();
        if (cbH1.Checked == true)
        {
            listHobbies.Add(cbH1.Text);
        }
        if (cbH2.Checked == true)
        {
            listHobbies.Add(cbH2.Text);
        }
        if (cbH3.Checked == true)
        {
            listHobbies.Add(cbH3.Text);
        }
        if (cbH4.Checked == true)
        {
            listHobbies.Add(cbH4.Text);
        }
        //通过 e.NewValues["Hobbies"]赋值
        e.NewValues["Hobbies"] = string.Join(",", listHobbies.ToArray());
    }
    protected void ASPxGridView1_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
    {
        //在RowUpdating时,将当前时间赋值给“创建时间列”ModifyTime赋值
        e.NewValues["ModifyTime"] = DateTime.Now;

        GridViewDataColumn columnHobbies = ASPxGridView1.Columns["Hobbies"] as GridViewDataColumn;//取出GridView的Column
        //通过ASPxGridView1.FindEditRowCellTemplateControl找出自定义的CheckBox
        ASPxCheckBox cbH1 = (ASPxGridView1.FindEditRowCellTemplateControl(columnHobbies, "ASPxCheckBox_H1") as ASPxCheckBox);
        ASPxCheckBox cbH2 = (ASPxGridView1.FindEditRowCellTemplateControl(columnHobbies, "ASPxCheckBox_H2") as ASPxCheckBox);
        ASPxCheckBox cbH3 = (ASPxGridView1.FindEditRowCellTemplateControl(columnHobbies, "ASPxCheckBox_H3") as ASPxCheckBox);
        ASPxCheckBox cbH4 = (ASPxGridView1.FindEditRowCellTemplateControl(columnHobbies, "ASPxCheckBox_H4") as ASPxCheckBox);

        ArrayList listHobbies = new ArrayList();
        if (cbH1.Checked == true)
        {
            listHobbies.Add(cbH1.Text);
        }
        if (cbH2.Checked == true)
        {
            listHobbies.Add(cbH2.Text);
        }
        if (cbH3.Checked == true)
        {
            listHobbies.Add(cbH3.Text);
        }
        if (cbH4.Checked == true)
        {
            listHobbies.Add(cbH4.Text);
        }
        //通过 e.NewValues["Hobbies"]赋值
        e.NewValues["Hobbies"] = string.Join(",", listHobbies.ToArray());
    }
}

完整源码,稍后上传...

博文作者:挪威森林(Coding of life)

博文出处:http://www.cnblogs.com/allenlf/

主要研究:Web开发框架、ORM、WCF、医疗行业软件开发(HRP、EMR、CP、OA)

版权归挪威森林博客园所有,转载请注明出处,谢谢合作

时间: 2024-11-05 18:41:01

DevExpress ASP.NET 使用经验谈(8)-ASPxGridView自定义列和基本事件的相关文章

DevExpress ASP.NET 使用经验谈(9)- Dev控件客户端事件 ClientSideEvents

上一节,已经介绍了ASPxGridView的自定义列和基本事件 ,本节接着将介绍Dev控件的客户端事件模型. 在上节示例基础上,我们增加一行菜单,使用Dev的ASPxMenu来实现,如下图所示. 图一 添加菜单的界面 增加菜单的代码如下: <dx:ASPxMenu ID="ASPxMenu1" runat="server" RenderMode="Lightweight" Width="100%" ItemAutoWid

DevExpress ASP.NET 使用经验谈(1)-XPO模型的创建

原文:DevExpress ASP.NET 使用经验谈(1)-XPO模型的创建 这个系列通过一些简单例子循序渐进,介绍DevExpress ASP.NET控件的使用.先来介绍一下XPO的使用,安装的DevExpress版本为DXperienceUniversal-12.2.4,使用Visual Studio 2012+Sql Server2005. 什么是XPO? XPO 是 eXpress Persistent Objects的缩写,它是DevExpress公司推出的一个运行在.NETFram

DevExpress ASP.NET 使用经验谈(4)-CriteriaOperator的使用

原文:DevExpress ASP.NET 使用经验谈(4)-CriteriaOperator的使用 上一节中,我们已经介绍了,使用CriteriaOperator表达式,获取对象数据. CriteriaOperator criteria = CriteriaOperator.Parse("[UserID]='" + obj.UserID + "'"); Users objnew = session.FindObject<Users>(criteria)

DevExpress ASP.NET 使用经验谈(2)-XPO对象的使用(使用默认数据连接)

原文:DevExpress ASP.NET 使用经验谈(2)-XPO对象的使用(使用默认数据连接) 接下来,我们通过一个控制台应用程序,介绍XPO对象的保存操作. 图一 添加新项目 图二 选择项目类型为控制台应用程序 查看生成的Program.cs代码文件,代码如下: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

DevExpress ASP.NET 使用经验谈(5)-通过ASPxGridView实现CRUD操作

这节,我们将通过使用DevExpress的ASPxGridView控件,实现对数据的CRUD操作. 首先,我们在解决方案中,添加一个网站: 图一 添加新网站 图二 添加DevExpress.Data.v12.2.dll,DevExpress.Xpo.v12.2.dll,以及XPOModel的引用 图三 从工具栏拖放ASPxGridView与XpoDataSource 图四 设置XpoDataSource的类型名称 TypeName,先选择控件,右键-属性(或点击右上角小箭头) 图五 点击Type

DevExpress ASP.NET 使用经验谈(6)-ASPxGridView通过属性配置界面展现

上一节中,我们通过简单的配置,通过ASPxGridView控件的使用,完成了对数据库表的CRUD操作. 这样的界面展现,功能是达到了,但是操作体验上,还是有所欠缺的. 图一 默认生成的列表界面 图二 默认编辑界面 接下来,我们通过以下几步简单的设置,使界面操作更美观,更符合实际需求. 第一步,我们将显示为文字操作的Edit,New,Delete修改为图片,通过属性 ButtonType="Image" 来实现. <dx:GridViewCommandColumn VisibleI

DevExpress ASP.NET 使用经验谈(2)-XPO对象的使用(Save操作)

接下来,我们通过一个控制台应用程序,介绍XPO对象的保存操作. 图一 添加新项目 图二 选择项目类型为控制台应用程序 查看生成的Program.cs代码文件,代码如下: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DevConsole { class Program { static voi

DevExpress Asp.net ASPxTreeList的基本使用之一

DevExpress Asp.net ASPxTreeList的基本使用之一 目录(?)[+] 本文来自CSDN博客转载请标明出处httpblogcsdnnetwServicesarchive200907254378771aspx DevExpress Aspnet ASPxTreeList的基本使用之一 本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/wServices/archive/2009/07/25/4378771.aspx DevExpress Asp

【DevExpress v17.2新功能预告】DevExpress ASP.NET Scheduler新的自适应功能

自适应Web设计可以帮助您解决各种尺寸的屏幕问题,网站的自适应网页设计可帮助您解决用户使用不同大小屏幕显示数据的问题. 在v17.2中,我们最大化了ASP.NET Scheduler的视图和可视化元素,以适应其父容器的宽度.以下ASP.NET Scheduler元素现在支持自适应布局: Agenda View Agenda View现在完全自适应.以下的Agenda View元素将自动调整为当前客户端宽度: "Date Header" column "Appointment