【问题标题】:Hiding/Showing Links in Telerik MVC2 Grid在 Telerik MVC2 网格中隐藏/显示链接
【发布时间】:2010-10-27 14:54:56
【问题描述】:

我有一个 Telerik MVC2 网格,其中有一列如下:

columns.Bound(c => c.CustomerID)
       .Format(Html.ActionLink("Close", "CloseCustomer", new { Id = "{0}"}).ToString())
       .Encoded(false)
       .Title(String.Empty)
       .Width(80);

正在使用的对象还包括一个关闭标志,如果客户已经关闭,我希望能够让它使链接不可见(正在使用的对象也有一个 ClosedFlag 以及 CustomerID)。

有没有一种简单的方法可以做到这一点,还是我必须使用自定义模板?

【问题讨论】:

  • 您使用的是服务器端还是客户端绑定?

标签: asp.net-mvc telerik


【解决方案1】:

你可以定义如下:

<%
 Html.Telerik().Grid(Model)
 .Columns(columns =>
                     {
                         columns.Template(m =>
                                            {
                                             if (!m.Closed)
                                              {
    %>
    <a id='closed'>You hyperlink here</a>
    <%
        }
                                              })
 //blah blah and the rest of the column defiitions

【讨论】:

    【解决方案2】:

    我以前在我的一个项目中做过这个。请看一下。我正在使用我们通常使用的 Ajax.ActionLink

            <% Html.Telerik().Grid<TMG.Framework.Web.MVC.Models.EnrolRegAcntDescriptor>()
           .HtmlAttributes("style")
       .Name("Grid")
    
       .DataKeys(datakeys => datakeys.Add(m => m.enrollment_account_id))
       .Columns(columns =>
       {
           columns.Bound(m => m.NPI).Width(70);
           columns.Bound(m => m.PIN).Title("Legacy PIN").Width(70);
           // columns.Bound(m => m.EnrolRegAcntDescriptor.bank_account_no).Title("Account No.");
           columns.Bound(m => m.aba_routing_no).Title("ABA Routing");
           columns.Bound(m => m.financial_inst).Title("Financial Inst").Width(50);
           columns.Bound(m => m.Name).Title("Authorized User").Width(90);
           columns.Bound(m => m.status).Title("Status").Width(80);
           columns.Bound(m => m.EnrollmentAuthorityID).Title("");
           columns.Bound(m => m.ProviderApplicantID).Title("");
           columns.Bound(m => m.enrol_status_id).Title("");
                columns.Template(m => m.status)
                 .ClientTemplate(
                 Ajax.ActionLink("Delete ", "DeleteEnrolAccountByID",
                 new
                 {
                     ProviderApplicantID = "<#=ProviderApplicantID#>",
                     enrol_status_id = "<#=enrol_status_id #>",
                 EnrollmentAuthorityID = "<#=EnrollmentAuthorityID#>",
                 enrollment_account_id = "<#=enrollment_account_id#>" },
                 new AjaxOptions { UpdateTargetId = "EnrolRegisterComplete", HttpMethod = "Delete" },
                 new
                 {
                     name = "deleteStatus",
                     status = "<#=status#>",
                     enrollment_account_id = "<#=enrollment_account_id#>",
                     EnrollAuthorityID = "<#=EnrollmentAuthorityID#>",
                     ProviderApplicantID = "<#=ProviderApplicantID#>",
                     enrol_status_id = "<#=enrol_status_id #>",
                    // onclick = "return confirm('Are you sure you want to delete this User?');"
                 }).ToHtmlString());
       }).ClientEvents(ev => {ev.OnDataBound("onGridBound"); })          
        .DataBinding(dataBinding => dataBinding.Ajax().Select("ajaxIndex", "EnrolRegister"))
         .Footer(true).Sortable()
         .Scrollable()
         .Pageable(pager=> pager.PageSize(10))
        .Render(); %>
    
        <script type="text/javascript" >
            function onGridBound(e) {
    
                $("a[name='deleteStatus']").each(function (e) {
                    if ($(this).attr("status") != 'Enrolled') {
                        $(this).hide();
                    } //, "disabled");
                });
            }
        </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-16
      • 2021-07-28
      • 1970-01-01
      • 1970-01-01
      • 2011-02-14
      • 1970-01-01
      • 2017-05-01
      • 1970-01-01
      相关资源
      最近更新 更多