Asp.net mvc 2 如何定制并使contrib grid时尚
到目前为止,我已经使用这种编码来查看我的mvc contrib网格…当我绑定网格时,它变得太大,最后一列超出了页面…请说明如何减小大小并使 网格有多时尚Asp.net mvc 2 如何定制并使contrib grid时尚,asp.net-mvc-2,mvccontrib,Asp.net Mvc 2,Mvccontrib,到目前为止,我已经使用这种编码来查看我的mvc contrib网格…当我绑定网格时,它变得太大,最后一列超出了页面…请说明如何减小大小并使 网格有多时尚 <%= Html.Grid<Product>(Model) .Columns(column => { column.For(c => c.ProductID); column.For(c => c.ProductName);
<%= Html.Grid<Product>(Model)
.Columns(column =>
{
column.For(c => c.ProductID);
column.For(c => c.ProductName);
column.For(c => c.SupplierID);
column.For(c => c.CategoryID);
column.For(c => c.QuantityPerUnit);
column.For(c => c.UnitPrice);
column.For(c => c.UnitsInStock);
column.For(c => c.UnitsOnOrder);
column.For(c => c.ReorderLevel);
column.For(c => c.Discontinued);
column.For(c => Html.ActionLink("Details", "Details", new { id = c.ProductID })).InsertAt(0).Encode(false);
column.For(c => Html.ActionLink("Edit", "Edit", new { id = c.ProductID })).InsertAt(1).Encode(false);
column.For(c => Html.ActionLink("Create", "Create", new { id = c.ProductID })).InsertAt(2).Encode(false);
column.For(c => Html.ActionLink("Delete", "Delete", new { id = c.ProductID })).InsertAt(3).Encode(false);
}
)
%>
{
column.For(c=>c.ProductID);
column.For(c=>c.ProductName);
column.For(c=>c.SupplierID);
列.For(c=>c.CategoryID);
column.For(c=>c.QuantityPerUnit);
列。用于(c=>c.单价);
列.For(c=>c.UnitsInStock);
column.For(c=>c.unitsOrder);
column.For(c=>c.reordlevel);
列.For(c=>c.已终止);
column.For(c=>Html.ActionLink(“Details”,“Details”,new{id=c.ProductID})).InsertAt(0).Encode(false);
column.For(c=>Html.ActionLink(“编辑”,“编辑”,new{id=c.ProductID})).InsertAt(1).Encode(false);
column.For(c=>Html.ActionLink(“Create”,“Create”,new{id=c.ProductID})).InsertAt(2).Encode(false);
column.For(c=>Html.ActionLink(“Delete”,“Delete”,new{id=c.ProductID})).InsertAt(3).Encode(false);
}
)
%>
您可以为每列定义宽度或自定义CSS类。这样可以限制其大小:
column.For(c => c.ProductID)
.Attributes(gr => new Hash(@width => "15%"));
或CSS类:
column.For(c => c.ProductID)
.Attributes(gr => new Hash(@class => "productId"));
您还可以将整个网格放入一个具有固定宽度的div中。以下是我如何使用交替行和颜色设置网格样式的方法
<%Html.Grid<UserSummaryModelDetails>(Model.Users)
.Columns(column =>
{
column.For(x => x.FullName).Named("Name").Attributes(x => new Dictionary<string, object> { { "valign", "top" } });
column.For(x => x.Division).Attributes(x => new Dictionary<string, object> { { "valign", "top" } });
})
.RowStart((p,row) => {
if (!row.IsAlternate) { %>
<tr class="gridrow_alternate">
<% } else { %>
<tr>
<% }
})
.HeaderRowAttributes(new Dictionary<string, object> { { "style", "height: 25px;" } })
.Empty("No users found")
.Attributes(@class => "table-list")
.Render();
%>
.table-list
{
clear: both;
width: 800px;
height: 100%;
border: solid 1px #e8eef4;
border-collapse: collapse;
overflow: visible;
margin-top: 10px;
}
.table-list td
{
padding: 5px;
border: solid 1px #e8eef4;
overflow: visible;
}
.table-list tr
{
height: 95px;
overflow: visible;
}
.table-list th
{
padding: 6px 5px;
text-align: left;
background-color: #e8eef4;
border: solid 1px #e8eef4;
overflow: visible;
}
.table-list .gridrow_alternate
{
background-color: #eee;
}