我正在尝试向mvc网格视图列添加多个设置。我知道如何将一个特定设置应用于列。我浏览了他们的网站文档,但无法找到这样的例子。我知道它可以完成,可能很容易,但无法在任何地方找到它的例子。
@{
var grid = Html.DevExpress().GridView(
settings =>
{
settings.Name = "gvMyGridView";
settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);
//Allows sorting etc
settings.CallbackRouteValues = new { Controller = "Home", Action = "MyGridPartial" };
settings.ClientSideEvents.BeginCallback = "OnBeginCallback";
settings.Columns.Add("ColumnA").SortOrder = DevExpress.Data.ColumnSortOrder.Ascending;
//settings.Columns.Add("ColumnA").Width = Unit.Pixel(75);
//As you can see above i want sort order set and the width set but am unable to do so
settings.Columns.Add("ColumnB").Width = Unit.Pixel(175);
settings.Columns.Add("ColumnC").Width = Unit.Pixel(175);
//Filter settings
settings.Settings.ShowFilterRow = true;
settings.Settings.ShowFilterRowMenu = true;
settings.CommandColumn.ClearFilterButton.Visible = true;
//Inline editing
settings.KeyFieldName = "Id";
});
if (ViewData["EditError"] != null){
grid.SetEditErrorText((string)ViewData["EditError"]);
}
}
@grid.Bind(Model).GetHtml()
我上面的例子非常自我解释。也许我必须在其自己的添加属性上创建我的列,然后手动添加它。不确定,因为这是我第一次使用MVC Devexpress Gridviews。非常感谢任何建议。
答案 0 :(得分:16)
settings.Columns.Add(column =>
{
column.FieldName = "Title";
column.Width = System.Web.UI.WebControls.Unit.Percentage(30);
column.SortOrder = DevExpress.Data.ColumnSortOrder.Ascending;
//other settings for column
});
答案 1 :(得分:1)
这是另一种方式:
var column = settings.Columns.Add("ColumnA", "ColumnADisplay");
column.SortOrder = DevExpress.Data.ColumnSortOrder.Ascending;
column.Width = Unit.Pixel(75);
答案 2 :(得分:0)
结束了自己创建列。
var column = new MVCxGridViewColumn("ColumnA", MVCxGridViewColumnType.Default);
column.Caption = "ColumnADisplay";
column.SortOrder = DevExpress.Data.ColumnSortOrder.Ascending;
column.Width = Unit.Pixel(75);
settings.Columns.Add(column);
答案 3 :(得分:0)
有什么用:
settings.Columns.Add(new MVCxGridViewColumn("ColumnA", MVCxGridViewColumnType.Default)
{
Caption = "ColumnADisplay",
vSortOrder = DevExpress.Data.ColumnSortOrder.Ascending,
Width = Unit.Pixel(75)
});