troubleshooting Question

C# inheriting a Gridview

Avatar of A_x_e_l
A_x_e_lFlag for Ireland asked on
3 Comments1 Solution1607 ViewsLast Modified:
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


Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros