(转载)DevExpress ASPxGridView 使用文档四:数据源

摘要:
“InsertCommand=”INSERTINTO[客户]([客户ID],[公司名称],[联系人名称],[ContactTitle],[地址],[城市],[地区],[邮政编码],[国家],[电话],[传真])VALUES(“UpdateCommand=”UPDATE[Customers]SET[CompanyName]=?,[ContactName]=?,[ContactTitle]=?,[地址]=?,[城市]=?,[区域]=?,[PostalCode]=?,[国家]=?,[电话]=?,[传真]=?WHERE[客户ID]=?“/˃˂asp:AccessDataSourcerunat=”server“DataFile=”~/App_Data/wind。mdb“OnDeleting=”AccessDataSource1_ Modification“OnInserting=”AccessDataSource1_ Modifying“OnUpdating=”AccessDataSource1_ modification“SelectCommand=”SELECT*FROM[客户]“DeleteCommand=”DELETEFROM[客户]WHERE[客户ID]=?“InsertCommand=”INSERTINTO[客户]([客户ID],[公司名称],[联系人名称],[ContactTitle],[地址],[城市],[地区],[邮政编码],[国家],[电话],[传真])VALUES(“UpdateCommand=”UPDATE[Customers]SET[CompanyName]=?,[ContactName]=?,[城市]=?,[区域]=?,[国家]=?WHERE[客户ID]=?

转载请注明出处:http://surfsky.cnblogs.com/

---------------------------------------------------------
-- DataSource 支持的数据源
--     DataTable
--     IList
--     BindingList
--     XXXDataSource
---------------------------------------------------------
DataTable
    grid.DataSource = dt;
    grid.DataBind();
    
IList
    int articleId = Convert.ToInt32(Request.QueryString["articleId"]);
    IList<BlogArticleImage> images = BlogArticleImage.ListArticleImages(articleId);
    this.gvImages.KeyFieldName = "ImageId";
    this.gvImages.DataSource = images;
    this.gvImages.DataBind();

BindingList
    private void CreateQuotes() 
    {
        BindingList<Quote> res = new BindingList<Quote>();
        foreach(string name in names) 
        {
            Quote q = new Quote(name);
            q.Value = (decimal)GetRandom().Next(800, 2000) / (decimal)10;
            res.Add(q);
        }
        Session["Quotes"] = res;
    }


AccessDataSource
    <asp:AccessDataSource runat="server" DataFile="~/App_Data/nwind.mdb"
        SelectCommand="SELECT * FROM [Customers]" 
        DeleteCommand="DELETE FROM [Customers] WHERE [CustomerID] = ?" 
        InsertCommand="INSERT INTO [Customers] ([CustomerID], [CompanyName], [ContactName], [ContactTitle], [Address], [City], [Region], [PostalCode], [Country], [Phone], [Fax]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" 
        UpdateCommand="UPDATE [Customers] SET [CompanyName] = ?, [ContactName] = ?, [ContactTitle] = ?, [Address] = ?, [City] = ?, [Region] = ?, [PostalCode] = ?, [Country] = ?, [Phone] = ?, [Fax] = ? WHERE [CustomerID] = ?"
        />
    <asp:AccessDataSource runat="server" DataFile="~/App_Data/nwind.mdb" 
        OnDeleting="AccessDataSource1_Modifying" OnInserting="AccessDataSource1_Modifying" OnUpdating="AccessDataSource1_Modifying"
        SelectCommand="SELECT * FROM [Customers]" DeleteCommand="DELETE FROM [Customers] WHERE [CustomerID] = ?" 
        InsertCommand="INSERT INTO [Customers] ([CustomerID], [CompanyName], [ContactName], [ContactTitle], [Address], [City], [Region], [PostalCode], [Country], [Phone], [Fax]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" 
        UpdateCommand="UPDATE [Customers] SET [CompanyName] = ?, [ContactName] = ?, [City] = ?, [Region] = ?, [Country] = ? WHERE [CustomerID] = ?">
        <DeleteParameters>
            <asp:Parameter Name="CustomerID" Type="String" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="CompanyName" Type="String" />
            <asp:Parameter Name="ContactName" Type="String" />
            <asp:Parameter Name="City" Type="String" />
            <asp:Parameter Name="Region" Type="String" />
            <asp:Parameter Name="Country" Type="String" />
        </UpdateParameters>
    </asp:AccessDataSource>
    protected void AccessDataSource1_Modifying(object sender, SqlDataSourceCommandEventArgs e) {
       DemoSettings.AssertNotReadOnly();
    }
    用代码实现
        AccessDataSource ds = new AccessDataSource();
        ds.DataFile = AccessDataSource1.DataFile;
        ds.SelectCommand = "select Photo from [Employees] where employeeid=" + id;
        DataView view = (DataView)ds.Select(DataSourceSelectArguments.Empty);
        if(view.Count > 0) return view[0][0] as byte[];
        return null;

ObjectDataSource
    <asp:ObjectDataSource runat="server" 
        TypeName="Quotes"
        SelectMethod="LoadQuotes" 
        />
    <asp:ObjectDataSource runat="server" 
        DataObjectTypeName="PersonRegistration"
        TypeName="MyPersonProvider" 
        SelectMethod="GetList" UpdateMethod="Update" InsertMethod="Insert"
        />
    <asp:objectDataSource runat="server"
        typename="PersonManager"
        selectMethod="SelectPersons"
        deleteMethod="DeletePerson"
        updateMethod="UpdatePerson"
        insertMethod="InsertPerson" >
        <insertParameters>
            <asp:parameter name="Id" type="Int32" />
        </insertParameters>
    </asp:objectDataSource>
    
ObjectDataSource.Parameters
    <SelectParameters> 
        <asp:SessionParameter Name="IGYSID" SessionField="ID" Type="Int32" /> 
        <asp:SessionParameter DefaultValue="0" Name="ICGFS" SessionField="ICGFS" Type="Int32" /> 
    </SelectParameters> 
    <UpdateParameters> 
        <asp:Parameter Name="IWZID" /> 
        <asp:Parameter Name="IGYSID" /> 
        <asp:Parameter Name="ICGMXID" /> 
        <asp:Parameter Name="IGYSBJID" /> 
        <asp:Parameter Name="NBJ" /> 
        <asp:Parameter Name="CBZ" /> 
    </UpdateParameters> 
    <UpdateParameters>
        <asp:FormParameter FormField="makeid" Name="MakeID" Type="String" />
        <asp:FormParameter FormField="name" Name="Name" Type="String" />
        <asp:FormParameter FormField="id" Name="ID" Type="String" ConvertEmptyStringToNull="False" />
    </UpdateParameters>


ObjectDataSource 使用的类
    (以下代码整理并修改至《ASP.NET 2.0 Revealed》P71-P78)
    (另外一个购物篮的例子,参考P138)
    public class Person
    {
        private int id;
        private string firstName;
        private string lastName;

        public int Id {...}
        public string FirstName {...}
        public string LastName {...}
        
        public Person(int id, string firstName, string lastName)
        {
            this.id = id;
            this.firstName = firstName;
            this.lastName = lastName;
        }
    }
    public class PersonCollection : List<Person> {}
    public class PersonManager
    {
        private const string personsKey = "persons";
        
        public PersonCollection SelectPersons()
        {
            HttpContext context = HttpContext.Current;
            if (context.Application[personKey] == null)
            {
                PersonCollection persons = new PersonCollection();
                persons.Add(new Person(0, "Patrick", "Lorenz"));
                persons.Add(new Person(0, "Patrick", "Lorenz"));
                persons.Add(new Person(0, "Patrick", "Lorenz"));
                persons.Add(new Person(0, "Patrick", "Lorenz"));
                context.Application[personKey] = persons;
            }
            return context.Application[personKey] as PersonCollection;
        }
        
        public Person SelectPerson(int id)
        {
            foreach (Person p in SelectPersons())
                if (p.Id == id)
                    return p;   
            return null;
        }
        
        public void DeletePerson(int id)
        {
            PersonCollection persons = (Application[personKey] as PersonCollections);
            Person person = SelectPerson(id);
            if (person != null)
                persons.Remove(person);
        }
        
        public void InsertPerson(int id, string firstName, string lastName)
        {
            PersonCollection persons = (Application[personKey] as PersonCollections);
            persons.Add(new Person(id, firstName, lastName));
        }
        
        public void UpdatePerson(int id, string firstName, string lastName)
        {
            Person person = SelectPerson(id);
            if (person != null)
            {
                person.FirstName = firstName;
                person.LastName = lastName;
            }
        }
    }

免责声明:文章转载自《(转载)DevExpress ASPxGridView 使用文档四:数据源》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇for循环嵌套单点登录理解下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

repeater简单应用(嵌套绑定)

眼看就要到上班的日子了,希望大家抓住宝贵时间能吃则吃,能乐则乐 咱还是节省网络资源,进入正题。。 说起repeater嵌套,好像从N久就有了,这个例子是前些日子做的,用了三层嵌套实现有,先说下,因为客观需求,并没有考虑到性能上的问题,所以可以看下其中的方法,至于别的可以自己探索下,呵呵。 功能是要实现一个下拉列表,列表顶层是可以动态设置的年份时间段,第二层...

spring boot 支持返回 xml

实现技术方式对比 JAXB(Java Architecture for XML Binding) 是一个业界的标准,可以实现java类和xml的互转 jdk中包括JAXB JAXB vsjackson-dataformat-xml spring boot中默认使用jackson返回json,jackson-dataformat-xml 中的 XmlMapp...

Unity面试题汇总(第一部分)

一、什么是渲染管道? 答:就是告诉GPU一些数据,经过一系列的操作,得到最终要显示的数据。渲染管道中的很多步骤,总的来说是将几何物体从一个坐标系变换到另一个坐标系中去。 主要步骤如下: 本地坐标系 -- 经过世界变换矩阵 --> 世界坐标系 -- 经过视图变换矩阵 --> 视图坐标系 -- 经过投影变换矩阵 --> 投影坐标系 -- 经过...

sscanf函数用法详解

名称: sscanf() - 从一个字符串中读进与指定格式相符的数据. 函数原型: Int sscanf( string str, string fmt, mixed var1, mixed var2 … ); int scanf( const char *format [,argument]… ); 说明: sscanf与scanf类似,都是用于输入的,...

mysql-5.6.27源码安装及错误解决办法

环境:centos6.5.x86_64 wgethttp://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.27.tar.gz yum install -y cmake 当然也可以自己下载源码包安装,为方便就Yum安装了 useradd -s /sbin/nologin mysql tar zxvf mysql-...

序列化 反序列化 MessagePack for C#

阅读目录 快速序列化组件MessagePack介绍 简介 使用 快速开始 分析器 内置的支持类型 对象序列化 DataContract兼容性 序列化不可变对象(序列化构造器) 序列化回调 Union Dynamic(Untyped)反序列化 Object 类型序列化 Typeless 性能 反序列化中每个方法的性能 LZ4压缩 与protobuf,JS...