DevExpress MVC GridView:使用 DetailRowGetButtonVisibility

发布于 2024-12-13 07:20:02 字数 1203 浏览 2 评论 0原文

是否可以在 ASP.NET MVC 中使用 RowGetButtonVisibility 事件? 在“正常”ASP.NET DevExpress 中,使用如下描述:

http://documentation.devexpress.com /#AspNet/DevExpressWebASPxGridViewASPxGridView_DetailRowGetButtonVisibilitytopic

我希望有可能显示/隐藏 GridView 中的详细信息按钮。

有什么想法可以做到这一点吗?

像这样的东西不起作用:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<FOO>" %>
<%
Html.DevExpress().GridView(settings =>
{
    settings.Name = "resultsTable";
    settings.KeyFieldName = "ResultId";
    settings.CallbackRouteValues = new { Controller = "Results", Action = "ResultsPartial" };
    settings.Width = Unit.Percentage(100);
    settings.Height = Unit.Percentage(100);

    //...

    settings.PreRender = (sender, e) =>
    {
        MVCxGridView grid = (MVCxGridView)sender;
        grid.DetailRowGetButtonVisibility += (s_, e_) =>
        {
            if (some_condition == true)
            e_.ButtonState = GridViewDetailRowButtonState.Hidden;
        };
    };
})
.Bind(Model.Results)
.Render();

Is it possible to use the event RowGetButtonVisibility in ASP.NET MVC?
In "normal" ASP.NET DevExpress is using this like described here:

http://documentation.devexpress.com/#AspNet/DevExpressWebASPxGridViewASPxGridView_DetailRowGetButtonVisibilitytopic

I want to have the possibility to show/hide the detail button within the GridView.

Any ideas to do this?

Something like this is not working:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<FOO>" %>
<%
Html.DevExpress().GridView(settings =>
{
    settings.Name = "resultsTable";
    settings.KeyFieldName = "ResultId";
    settings.CallbackRouteValues = new { Controller = "Results", Action = "ResultsPartial" };
    settings.Width = Unit.Percentage(100);
    settings.Height = Unit.Percentage(100);

    //...

    settings.PreRender = (sender, e) =>
    {
        MVCxGridView grid = (MVCxGridView)sender;
        grid.DetailRowGetButtonVisibility += (s_, e_) =>
        {
            if (some_condition == true)
            e_.ButtonState = GridViewDetailRowButtonState.Hidden;
        };
    };
})
.Bind(Model.Results)
.Render();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

萌吟 2024-12-20 07:20:02

我想我会在 SetDataItemTemplateContent 中使用纯 html 按钮。

我做了类似的事情,使用可以扩展的简单 if 来处理链接的输出。我想它也应该适合你。

var linkWeb = settings.Columns.Add("", "Web");
linkWeb.SetDataItemTemplateContent(c =>
{
   DevExpressHelper.WriteLineToResponse((DataBinder.Eval(c.DataItem, "UrlWeb") != null && DataBinder.Eval(c.DataItem, "UrlWeb") != "") ? "<a href=\"" + DataBinder.Eval(c.DataItem, "UrlWeb") + "\" target=\"_blank\" title=\"Url\"><img src=\"" + Url.Content("~/content/img/url.png") + "\" alt=\"Url\" /></a>" : "");
});

在此 html 代码中,您可以附加对所需回调操作的调用。如果我没记错的话,应该是这样的

mygrid.UpdateEdit();

希望有帮助。

I think I will go with pure html button inside the SetDataItemTemplateContent.

I did something like that to handle the output of a link using a simple if that you can extend. I guess it should work also for you.

var linkWeb = settings.Columns.Add("", "Web");
linkWeb.SetDataItemTemplateContent(c =>
{
   DevExpressHelper.WriteLineToResponse((DataBinder.Eval(c.DataItem, "UrlWeb") != null && DataBinder.Eval(c.DataItem, "UrlWeb") != "") ? "<a href=\"" + DataBinder.Eval(c.DataItem, "UrlWeb") + "\" target=\"_blank\" title=\"Url\"><img src=\"" + Url.Content("~/content/img/url.png") + "\" alt=\"Url\" /></a>" : "");
});

Inside this html code you could attach a call to the callback action you need. If i remember right, it should be something like that

mygrid.UpdateEdit();

Hope it helps.

请叫√我孤独 2024-12-20 07:20:02

我按照 DevExpress 论坛中所述解决了我的问题:

http:// Community.devexpress.com/forums/p/105806/358003.aspx#358003

我第一次尝试附加事件是正确的,但在 PreRender 上却不是。 DataBound 是正确使用的事件。

I solved my problem as described in the DevExpress-Forum here:

http://community.devexpress.com/forums/p/105806/358003.aspx#358003

My first try with attaching to the event was right, but not at PreRender. DataBound is the right event to use.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文