use images instead of text in webgrid asp mvc

为君一笑 提交于 2020-01-04 08:05:31

问题


How can I change the action links in this webgrid into images? ps: I want all the images to appear in the same column

@{
var grid = new WebGrid(Model, canPage:true ,canSort:true, rowsPerPage :6);
grid.Pager(WebGridPagerModes.NextPrevious);
    @grid.GetHtml(tableStyle: "webGrid", htmlAttributes: new { id = "datatable" },
    headerStyle: "Header",
    alternatingRowStyle: "alt",
    columns: grid.Columns(grid.Column(header: "", format: (item) =>
 new HtmlString(
       Html.ActionLink("Détails", "Details", new { id = item.id_client }).ToString() +
       Html.ActionLink("Modifier", "Edit", new { id = item.id_client }).ToString() +
                Html.ActionLink("Supprimer", "Delete", new { id = item.id_client }).ToString()
 )),
    grid.Column("Nom"),
    grid.Column("Prenom", "Prénom"),
    grid.Column("Email")));


                    }

回答1:


I've solved this using css classes

@{
         var grid = new WebGrid(Model, canPage:true ,canSort:true, rowsPerPage :6);
            grid.Pager(WebGridPagerModes.NextPrevious);
            @grid.GetHtml(tableStyle: "webGrid", htmlAttributes: new { id = "datatable" },
            headerStyle: "webgrid-header",
            selectedRowStyle : "webgrid-selected-row",
            footerStyle : "webgrid-footer",
            rowStyle: "webgrid-row-style",
            alternatingRowStyle: "webgrid-alternating-row",
            columns: grid.Columns(
            grid.Column(header: "", format:  (item) =>
            Html.ActionLink("Détails", "ObtenirDifficulte", new { id = item.id_diff}, 
            new { @class = "details" }), style: "actions"),
            grid.Column(header: "", format:  (item) => Html.ActionLink("Modifier", 
            "Edit",
            new { id = item.id_diff }, new { @class = "modifier" }),style : "actions"),
            grid.Column(header: "", format: (item) => Html.ActionLink("Supprimer",
            "Delete", new { id = item.id_diff }, new { @class = "supprimer" }),
            style: "actions"),
            grid.Column("titre", "Titre"),
            grid.Column("description", "Description"),
            grid.Column("tache.nom_tache", "Tâche correspondante")
            ));
}

And here are the css classes

.modifier
{
    background: url(../Images/modifier.png) no-repeat top left ;
    display: block;
    width: 18px;
    height: 24px;
    text-indent: -9999px;
}
.details
{
    background: url(../Images/details.png) no-repeat top left ;
    display: block;
    width: 26px;
    height: 32px;
    text-indent: -9999px;
}
.supprimer
{
    background: url(../Images/supprimer.png) no-repeat  ;
    display: block;
    width: 18px;
    height: 24px;
    text-indent: -9999px;
}


来源:https://stackoverflow.com/questions/11808483/use-images-instead-of-text-in-webgrid-asp-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!