如何使用aspx在mvc3中创建webgrid? [英] How to create webgrid in mvc3 using aspx?
本文介绍了如何使用aspx在mvc3中创建webgrid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用webgrid来显示数据库中的数据。
我创建了一个数据库实体模型类,其中包含表的字段。
我正在创建另一个模型从存储过程调用数据并进入数据库实体模型类列表的类。
我创建一个部分视图来显示webgrid。
任何人都可以帮助我这个?
解决方案
< p> WebGrid示例使用文本框和复选框< ; / p >
<% var list = new []
{
new {StudentId = 1 ,Name = Name1 ,Cond = true },
new {StudentId = 2 ,Name = Name3,Cond = false },
new {StudentId = 3 ,Name = Name3,Cond = true },
new {StudentId = 4 ,Name = Name4 ,Cond = true },
new {StudentId = 5 ,Name = Name5,Cond = false },
new {StudentId = 6 ,Name = Name6,Cond = true },
new {StudentId = 7 ,Name = Name7,Cond = true },
new {StudentId = 8 ,Name = Name8, Cond = true },
new {StudentId = 9 ,Name = Name9,Cond = true },
new {StudentId = 10 ,Name = Name10,Cond = true },
new {StudentId = 11 ,Name = Name11,Cond = true }
};
WebGrid studentGrid = new WebGrid(list);
// studentGrid.Bind(list,autoSortAndPage:true,rowCount:3);
%>
<%=
studentGrid.GetHtml(htmlAttributes: new {id = grid},
alternatingRowStyle: altrow,
模式:WebGridPagerModes.All,
firstText: << First,
previousText: < Previous,
lastText: Last>>,
nextText: Next> ,
列:
new WebGridColumn []
{
studentGrid.Column( StudentId , Id),
studentGrid.Column( 名称, Name),
studentGrid.Column(columnName: 名称,header: 名称,格式:( item)= > Html.TextBox( st)),
studentGrid.Column(columnName: 名称,标题: 名称,格式:x = > Html.CheckBox( ts)),
studentGrid.Column(标题: 操作,
格式:item = >
{
string span = < span class = \1 \id = \{0} \> {1}< span>;
string action = item.Cond? 选择: 删除跨度>;
return Html.Raw( string .Format(span,item.StudentId,action)) ;
}),
studentGrid.Column(格式:(item)= > Html.ActionLink( 编辑, 编辑 , new {id = item.Cond})),
studentGrid.Column(格式:( item)= > Html.ActionLink( 删除, 删除, null , new {onclick = string .Format( deleteRecord('Cart','{0}'),item.Cond),@ class = 删除,href = JavaScrip t:void(0)}))
})
%>
I am using webgrid to display data from the database.
I am create a database entity model class which has fields of the table.
I am creating another model class which is calling data from a stored procedure and entering into database entity model class''s list.
I am creating a partial view to display webgrid.
Can anyone help me with this?
解决方案
<p>WebGrid Example With textbox and checkbox</p> <% var list = new[] { new { StudentId = 1, Name = "Name1", Cond = true }, new { StudentId = 2, Name = "Name3", Cond = false }, new { StudentId = 3, Name = "Name3", Cond = true }, new { StudentId = 4, Name = "Name4", Cond = true }, new { StudentId = 5, Name = "Name5", Cond = false }, new { StudentId = 6, Name = "Name6", Cond = true }, new { StudentId = 7, Name = "Name7", Cond = true }, new { StudentId = 8, Name = "Name8", Cond = true }, new { StudentId = 9, Name = "Name9", Cond = true }, new { StudentId = 10, Name = "Name10", Cond = true }, new { StudentId = 11, Name = "Name11", Cond = true } }; WebGrid studentGrid = new WebGrid(list); //studentGrid.Bind(list, autoSortAndPage: true, rowCount: 3); %> <%= studentGrid.GetHtml(htmlAttributes: new { id = "grid" }, alternatingRowStyle: "altrow", mode: WebGridPagerModes.All, firstText: "<<First", previousText: "<Previous", lastText: "Last>>", nextText: "Next >", columns: new WebGridColumn[] { studentGrid.Column("StudentId", "Id"), studentGrid.Column("Name", "Name"), studentGrid.Column(columnName: "Name", header: "Name", format: (item) => Html.TextBox("st")), studentGrid.Column(columnName: "Name", header: "Name", format: x => Html.CheckBox("ts")), studentGrid.Column(header: "Action", format: item => { string span = "<span class=\"1\" id=\"{0}\">{1}<span>"; string action = item.Cond ? "Select" : "Remove"; return Html.Raw(string.Format(span, item.StudentId, action)); }), studentGrid.Column(format: (item) => Html.ActionLink("Edit", "Edit", new { id = item.Cond })), studentGrid.Column(format:(item) => Html.ActionLink("Delete", "Delete", null, new {onclick=string.Format("deleteRecord('Cart', '{0}')", item.Cond), @class="Delete", href="JavaScript:void(0)"})) }) %>
这篇关于如何使用aspx在mvc3中创建webgrid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文