1

asp.net noob here. I'm trying to override/extend Gridview for paging as specified in this topic: Problem with Efficient Gridview paging without datasource control

code-behind:

namespace MyCode
{
    public partial class _Default : System.Web.UI.Page
    {
    ....
    }
}
namespace cly.Web.CustomControls
    {
         public class clyGridView : GridView
         {
          ...code
         }
    }

How would I declare this new gridview in my .aspx file? I have tried using the class as

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="MyCode._Default" %>
<%@ Import Namespace="cly.Web.CustomControls" %>    
...
<asp:clyGridView ID="MyResults" runat="server"> </asp:clyGridView>

but that doesn't work and I get this error

The type or namespace name 'clyGridView' does not exist in the namespace 'System.Web.UI.WebControls' (are you missing an assembly reference?)   
Community
  • 1
  • 1
user1384831
  • 219
  • 1
  • 5
  • 14

2 Answers2

2

You need to register a tag prefix for your custom control.

Add

<%@ Register tagprefix="cly" namespace="cly.Web.CustomControls" %>

to your page and use the tag prefix with your custom control

<cly:clyGridView ID="MyResults" runat="server"> </cly:clyGridView>
Filburt
  • 17,626
  • 12
  • 64
  • 115
  • I get the error: The name 'MyResults' does not exist in the current context. My codebehind isn't seeing the new clyGridView for some reason – user1384831 May 25 '12 at 17:52
  • `Results` doesn't occur in your sample code so this is an unrelated new problem. To be quite honest I don't think it's a good idea to create custom controls just after starting in ASP.NET. In 90% of all cases people try to invent functionality that is already there. – Filburt May 25 '12 at 17:57
  • Check your **Default.aspx.designer.cs** - it must contain `protected global::cly.Web.CustomControls.clyGridView MyResults;`. – Filburt May 27 '12 at 13:59
0

If your goal is only to make the paging efficient, you should only create a custom datasource.

Here is a tutorial that teaches you how to do it.

Creating a custom girdview is not needed.

If you implement the datasource properly, gridview will bind to it perfectly and you will get the efficient paging you desire.

nunespascal
  • 17,584
  • 2
  • 43
  • 46