Friday, March 11, 2016

How do I change what column headers say at a DevExpress MVC GridView?

Assuming something like this:

@Html.DevExpress().GridView(
settings =>
{
   settings.Name = "GridView";
   settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);
   settings.SettingsPager.PageSize = 32;
   settings.Settings.VerticalScrollBarMode = ScrollBarMode.Hidden;
   settings.Settings.VerticalScrollableHeight = 350;
   settings.ControlStyle.Paddings.Padding = System.Web.UI.WebControls.Unit.Pixel(0);
   settings.ControlStyle.Border.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(0);
   settings.ControlStyle.BorderBottom.BorderWidth =
         System.Web.UI.WebControls.Unit.Pixel(1);
   settings.Columns.Add("CityName");
   settings.Columns.Add("TimeZoneName");
}).Bind(Model).GetHtml()

 
 

How can we give friendlier names to the CityName and TimeZoneName columns? It turns out it's not too tough!

@Html.DevExpress().GridView(
settings =>
{
   settings.Name = "GridView";
   settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);
   settings.SettingsPager.PageSize = 32;
   settings.Settings.VerticalScrollBarMode = ScrollBarMode.Hidden;
   settings.Settings.VerticalScrollableHeight = 350;
   settings.ControlStyle.Paddings.Padding = System.Web.UI.WebControls.Unit.Pixel(0);
   settings.ControlStyle.Border.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(0);
   settings.ControlStyle.BorderBottom.BorderWidth =
         System.Web.UI.WebControls.Unit.Pixel(1);
   settings.Columns.Add("CityName");
   settings.Columns.Add("TimeZoneName");
   settings.Columns[0].Caption = "City";
   settings.Columns[1].Caption = "Timezone";
}).Bind(Model).GetHtml()

No comments:

Post a Comment