We help IT Professionals succeed at work.
Get Started

C# inheriting a Gridview

A_x_e_l asked
Last Modified: 2012-05-07
Hi I need to build a gridview control with a fixed header and scrolling contents - I have most of the code written but I would like to create a web user control from this - I do not want to compile this into a DLL just keep and use it (with source code) in the project. This project is for a big multinational customer and they have a strict approval process for Third party tools, so I have to roll my own. I seem to have problems using the correct base class - see my code below. I have tried to remove the Compiler errors I got by adding a name space but I get conflicting error messages about Namespaces vs. TagName.

With the usage below I am getting Unrecognized tag prefix or device filter 'uc1'. If I leave out the namespace from the Register line I get Element Scrollgridview is not a known element.

I am not sure whether the CodeFileBaseClass points to the correct Control, should I point it to the gridview? in which  assembly is this?

The syntax for assemplies is very complicated and not easy to understand for a C# newbie (I have done C++ for a lot of years 10 years ago, we used to program Windows based on a simple windows API - Petzold...)
<%@ Control Language="C#" AutoEventWireup="true"
 CodeFile="ScrollGridView.ascx.cs" Inherits="Genbase.ScrollGridView"
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Text; // for StringBuilder
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;  // GridView
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace Genbase
    public partial class ScrollGridView : System.Web.UI.WebControls.GridView
        protected override void OnPreRender(EventArgs e)
           // .. added code for injecting JScript to make the header non scrollable ...
           // .. added code for injecting JScript to make the header non scrollable ...
           // .. added code for injecting JScript to make the header non scrollable ...
        protected override void OnInit(EventArgs e)
            Attributes.Add("style", "table-layout:fixed;");
        protected override void Render(HtmlTextWriter writer)
            writer.Write("<div id=\"" + ClientID + "_HeaderDivider\"></div>");
            if (Rows.Count > 10)
                writer.Write("<div style=\"overflow-y: scroll; height: 152px\">");
            if (Rows.Count > 10)
            if (ShowFooter)
                writer.Write("<div id=\"" + ClientID + "_FooterDivider\"></div>");
<%@ Register TagPrefix="uc1" TagName="ScrollGridView" Src="ScrollGridView.ascx" Namespace="Genbase"  %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
                 <uc1:ScrollGridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
     DataKeyNames="ACCOUNT_NUM,ID,ID1,ID2" DataSourceID="SqlDataSource1">
                         <asp:BoundField DataField="status_desc" HeaderText="status_desc" SortExpression="status_desc" />
                         <asp:BoundField DataField="Status_1_desc" HeaderText="Status_1_desc" SortExpression="Status_1_desc" />
                         <asp:BoundField DataField="status_2_desc" HeaderText="status_2_desc" SortExpression="status_2_desc" />
                 <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CFISQLConnectionString %>"
                     SelectCommand="spOIStatusGet" SelectCommandType="StoredProcedure"></asp:SqlDataSource>

Open in new window

Watch Question
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE