在mvc3下使用infragistics控件,将odata+wcf传回的数据绑定到grid
2011-10-13 09:28
351 查看
参考文章:http://community.infragistics.com/blogs/taz_abdeali/archive/2011/05/09/using-netadvantage-jquery-grid-in-asp-net-mvc.aspx
1.添加引用
2.添加
3.在model中构建类 AccountModels
3.构建类BankAccount
4.controller定义
5.定义View
显示效果
1.添加引用
2.添加
3.在model中构建类 AccountModels
public class AccountModels { public static IQueryable<BankAccount> GetAccountList() { List<BankAccount> accountList = new List<BankAccount>(); DateTime date = DateTime.Now; for (int i = 1; i < 1001; i++) { accountList.Add(new BankAccount() { AccountNumber = i, AccountName = "Test" + i.ToString(), AccountDate = date, AccountType = "chk", AccountBalance = 12345678.90M } ); } return accountList.AsQueryable<BankAccount>(); } public static IQueryable<Product> GetProductList() { var context = new NorthwindEntities(new Uri("http://services.odata.org/Northwind/Northwind.svc/")); var products = from product in context.Products select product; //ViewData["ProductList"] = products.ToList(); return products.ToList().AsQueryable<Product>(); }
3.构建类BankAccount
public class BankAccount { public int AccountNumber { get; set; } public string AccountName { get; set; } public DateTime AccountDate { get; set; } public string AccountType { get; set; } public decimal AccountBalance { get; set; } }
4.controller定义
public class HomeController : Controller { public ActionResult Index() { ViewBag.Message = "Welcome to ASP.NET MVC!"; return View(); } public ActionResult About() { return View(); } [GridDataSourceAction] public ActionResult GetAccountList() { //return View(Models.AccountModels.GetAccountList()); return View(Models.AccountModels.GetProductList()); } }
5.定义View
@{ ViewBag.Title = "Home Page"; } @using Infragistics.Web.Mvc; @using MvcApplication5.Models; <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.min.js" type="text/javascript"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/jquery-ui.min.js" type="text/javascript"></script> <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.js"></script> <script src="@Url.Content("~/Scripts/IG/ig.ui.min.js")" type="text/javascript"></script> <h2>@ViewBag.Message</h2> <p> To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>. </p> <div> @( Html.Infragistics().Grid<MvcApplication5.NorthwindService.Product>() .ID("igGrid1") .Columns(column => { column.For(x => x.ProductID).DataType("int").HeaderText("Account Number"); column.For(x => x.ProductName).DataType("string").HeaderText("Account Name"); //column.For(x => x.AccountDate).DataType("date").HeaderText("Account Date"); //column.For(x => x.AccountType).DataType("string").HeaderText("Account Type"); //column.For(x => x.AccountBalance).DataType("number").HeaderText("Account Balance"); }) .Features(features => { features.Paging().PageSize(20).PrevPageLabelText("Previous").NextPageLabelText("NEXT"); features.Sorting().Mode(SortingMode.Single).ColumnSettings(settings => { settings.ColumnSetting().ColumnKey("AccountNumber").AllowSorting(true); }); features.Selection().MouseDragSelect(true).MultipleSelection(true).Mode(SelectionMode.Row); }) .ClientDataSourceType(ClientDataSourceType.JSON) .DataSourceUrl(Url.Action("GetAccountList")) .Width("40%") .Height("350") .LocalSchemaTransform(true) .DataBind() .Render() ) </div>
显示效果
相关文章推荐
- 在数据绑定控件中使用LinkButton传递参数方法
- 使用Repeater控件实现数据绑定
- WCF 使用 Https 绑定数据(包括分布式WCF事务配置方法)
- 数据绑定控件的使用和区别
- Gridview,datalist,repeater数据绑定控件使用说明
- 使用数据绑定控件实现增、删、改
- ASP.NET数据绑定GridView控件使用技巧
- Eval()、XPath() 和 Bind() 这类数据绑定方法只能在数据绑定控件的上下文中使用
- 使用【表格式】数据绑定控件
- 使用DataTable绑定DataGridView后,鼠标点击DataGridView控件时才会显示数据?
- C# 程序中如何向(DEV)ComboBoxEdit控件中添加下拉列表的值不使用数据绑定,就是使用代码添加
- 使用数据绑定控件GrideView的原因以及如何使用
- [转]Web页面报错: Eval()、XPath() 和 Bind() 这类数据绑定方法只能在数据绑定控件的上下文中使用
- Eval()、XPath() 和 Bind() 这类数据绑定方法只能在数据绑定控件的上下文中使用。 (FromView)
- 微软图表控件使用初探--数据绑定(交叉表)
- asp.net中使用分页控件,并绑定数据到GridView或Repeater
- dropdownlist控件的使用(数据绑定)
- ListView数据绑定控件的使用
- 在数据绑定控件GridView等模板中使用标准控件image