2011-02-02 62 views
0

我需要擴展Repeater控件,當沒有數據要顯示時不會顯示。 所以我添加了類庫項目到我的解決方案,並將該類添加到該類庫項目。擴展控件和使用問題

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Web.UI.WebControls; 
using System.Web.UI; 

namespace FRMControls 
{ 
    public class CustomRepeater:Repeater 
    { 
     public ITemplate EmptyDataTemplate { get; set; } 

     protected override void OnDataBinding(EventArgs e) 
     { 
      base.OnDataBinding(e); 

      if (this.Items.Count == 0) 
      { 
       EmptyDataTemplate.InstantiateIn(this); 
      } 
     } 
    } 
} 

寫完後,我添加了引用來使用這個庫。 我將控件添加到aspx頁面一樣,

<%@ Register TagPrefix="asp" Namespace="FRMControls" Assembly="FRMControls" %> 

,但我不能看到和使用的控制 我做錯了什麼?

+0

你如何約束控制?它應該在哪裏看到,你沒有看到什麼? – Oded 2011-02-02 10:16:30

+0

我應該這樣使用,但我不能在intellisense中看到asp:CustomRepeater。 – 2011-02-02 10:24:26

回答

1

檢查:

  • 您已經添加在ASP.NET項目類庫的引用?

  • 我從來沒有試過重新使用「asp」XML命名空間。我不會推薦使用它,因爲您將來可能會與Microsoft發生衝突,所以我建議您使用自定義的「frm」。因爲我從來沒有試過重複使用「asp」命名空間,所以也許這就是您的控件不能在intellisense菜單中列出的原因。

  • 您的類庫目標框架版本是否與您的ASP.NET應用程序相同?如果您使用的是3.5,則兩者都必須適用於.NET Framework 3.5或4.0,等等。

只是一個嘗試,註釋掉如果非這些已經解決了你的問題。