2011-02-02 59 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,等等。

只是一个尝试,注释掉如果非这些已经解决了你的问题。