简体   繁体   English

如何在GridView中添加最后一列

[英]How add last column in GridView

I need add last column "action", and set in cell href <a href="/?page=@Id">details</a> how do this in devexpress? 我需要添加最后一列“操作”,并在单元格href中设置<a href="/?page=@Id">details</a>在devexpress中如何进行?

@Html.DevExpress().GridView(
    settings =>
    {
        settings.Name = "gvGrouping";

        settings.Columns.Add("Id");//not visible
        settings.Columns.Add("Service", "Сервис");

    settings.Columns.Add("Action", "Action");//I have error

    }
    )

How I usually do it (don't know if it's THE best way, but it does the job): 我通常的操作方式(不知道这是否是最好的方法,但它能完成工作):

 settings.Columns.Add(column =>
                                {
                                 column.FieldName = "Id";
                                 column.Caption = " ";
                                 column.Settings.AllowAutoFilter = DefaultBoolean.False;
                                 column.Settings.AllowDragDrop = DefaultBoolean.False;
                                 column.Settings.AllowSort = DefaultBoolean.False;
                                });
 settings.CustomColumnDisplayText = (sender, e) =>
                                          {
                                                if (e.Column.FieldName == "Id")
                                                {
                                                     e.DisplayText = // put your actionlink here                                                                                       
                                                }
                                          };

This gives you the ability to put whetever you like in there (an image, a URL, etc..). 这样,您就可以在其中放置喜欢的图片(图像,URL等)。 You can access the value of the Id by calling 'e.Value' or args.GetFieldValue("") for another property. 您可以通过调用另一个属性的'e.Value'或args.GetFieldValue(“”)来访问Id的值。 Or you can just access the model (Model.blabId).. 或者,您可以只访问模型(Model.blabId)。

Hope this helps 希望这可以帮助

UPDATE: 更新:

I don't know how you've structured your grid, but this is how it should be (I think there is something wrong with the way you're calling the grid, that's why you're getting the error): 我不知道您是如何构建网格的,但是这应该是这样(我认为调用网格的方式出了点问题,这就是您得到错误的原因):

 Html.DevExpress().GridView(settings =>
    {
       //all your settings stuff in here
    }).Bind(Model.YourList).Render();

You could also use SetDataItemTemplateContent 您也可以使用SetDataItemTemplateContent

@Html.DevExpress().GridView(
    settings =>
    {
       var actionCol = settings.Columns.Add("Action");
       actionCol.SetDataItemTemplateContent(() =>
       { 
          Html.ActionLink("Action", "SomeAction", "SomeController", new { myParam =    Model.Param });
    } );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM