使用Dev ASPxGridView对接后台数据访问层
来源:互联网 发布:淘宝店铺手机端 编辑:程序博客网 时间:2024/06/10 13:51
使用Dev ASPxGridView对接后台数据访问层
默认ASPxGridView使用DataSource可以很方便,但SQL代码写在ASPX文件中,对于分层开发不力。所以尝试对接后台接口,然后通过自定义修改、插入、删除事件中调用后台接口来处理数据。对于动态绑定数据源,需要在ASPxGridView设计中先创建好要绑定的Column,并EnableEditing,EnableInserting,EnableDeleting
慧都解决方案(为您提供贴近企业应用的方案) HOOPS 3D Framework(3D框架功能集成) Thebrain7思维导图革命时代 DevExpress中文网using System;
using System.Collections.Generic;
using System.Data;
using DevExpress.Web.ASPxGridView;
using System.Web;
.using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Main : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GetData(ASPxGridView1);
}
protected void GetData(ASPxGridView grid)
{
List<Category> categories = new List<Category>();
DataSet ds= msSql.SqlExecuteDataSet("select * from categories");
foreach (DataTable table in ds.Tables)
{
foreach (DataRow row in table.Rows)
{
categories.Add(new Category(Convert.ToInt16(row[0]),
Convert.ToString(row[1]),Convert.ToString(row[2])));
}
}
grid.DataSource = categories;
grid.DataBind();
}
protected void UpdateData
(object CategoryID,object CategoryName, object Description)
{
string s = String.Format
("Update categories set CategoryName=
'{0}',Description='{1}'
where CategoryID={2}", CategoryName, Description, CategoryID);
msSql.SqlExecuteNonQuery(s);
}
protected void InsertData
object CategoryID,object CategoryName, object Description)
{
string s = String.Format("insert into categories
(CategoryID,CategoryName,Description) values
({0},'{1}','{2}')", CategoryID, CategoryName, Description);
msSql.SqlExecuteNonQuery(s);
}
.protected void DeleteData(object CategoryID)
{
string s = String.Format
("delete from categories where CategoryID={0}", CategoryID);
msSql.SqlExecuteNonQuery(s);
.}
protected void ASPxGridView1_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
{
UpdateData(e.OldValues["CategoryID"],e.NewValues["CategoryName"],
e.NewValues["Description"]);
e.Cancel = true;
(sender as ASPxGridView).CancelEdit();
GetData((sender as ASPxGridView));
}
protected void ASPxGridView1_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e)
{
DeleteData(e.Keys[0]);
e.Cancel = true;
GetData((sender as ASPxGridView));
}
protected void ASPxGridView1_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
{
InsertData(e.NewValues["CategoryID"],
e.NewValues["CategoryName"], e.NewValues["Description"]);
. e.Cancel = true;
(sender as ASPxGridView).CancelEdit();
GetData((sender as ASPxGridView));
}
}
public class Category
{
private int _CategoryID;
public int CategoryID
{
get { return _CategoryID; }
set { _CategoryID = value; }
}
public string CategoryName { get; set; }
public string Description { get; set; }
public Category(int categoryid, string categoryname, string description)
{
CategoryID = categoryid;
CategoryName = categoryname;
Description = description;
}
}
- 使用Dev ASPxGridView对接后台数据访问层
- DXPerience之ASPxGridView使用体会(一) 自定义数据后台处理
- ASPxGridView使用(2)数据导出
- Dev控件系列之ASPXGridview控件自主绑定数据
- Dev控件系列之ASPXGridview控件自主绑定数据
- JSP_strut2架构下前台使用canvas对接收到的后台数据画图的一种实现
- Dev 之ASPxGridView后台动态创建超链接以及读取动态字段
- 使用SubSonic生成数据访问层步骤
- 数据访问层SqlHelper的使用
- 数据访问层SqlHelper的使用
- 使用SubSonic生成数据访问层步骤
- 数据访问层使用存储过程分页
- Jquery跨域访问以及 .net后台对接的方式
- ASPxGridView后台嵌套
- DEV ASPXGRIDVIEW控件中的Findcontrol
- DEV ASPXGRIDVIEW控件中的Findcontrol
- 收藏:数据访问层
- 数据访问层DataAccess
- 云计算分布式架构综述
- Flight
- FME 坐标系转换
- struts 国际化总结
- 虚拟机栈和本地方法栈OOM测试2
- 使用Dev ASPxGridView对接后台数据访问层
- WTL之父Nenad Stefanovic访谈录_翻译中文版
- POJ 2104 归并树 or 划分树
- 非奇异矩阵的LU分解C++程序
- Asp.net 后台调用js方法
- 点覆盖的次数
- create tooltips using CSS transitions and the pseudo-classes :before and :after
- 通过先unlink()后close()创建安全的临时文件
- open vswitch研究:datapath