2010-10-27 36 views
2

我有一個Telerik的MVC2電網具有像一列:使用隱藏/顯示鏈接在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)。

有沒有一個簡單的方法來做到這一點,或者我必須使用自定義模板?

+0

您使用的是服務器端還是客戶端綁定? – 2010-10-27 15:00:47

+0

客戶端綁定。 – 2010-11-01 15:20:25

回答

0

您可以定義是這樣的:

<% 
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 
0

我曾在我的項目之一這樣做過。請看看它。我正在使用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> 
+0

這個答案對你有幫助嗎? – Ashes 2011-09-08 11:44:40