extending Datagrid - problem


G

Guest

Hi folks,
first off, I'm using Framework vs 1.1 with ASP.net and C#

I'm trying to extend the System.Web.UI.Webcontrols.DataGrid, and the only
thing I want to extend is the Render method (in order to add <thead> and
<tbody> elements)

so far so good

I've placed this code into another project called CustomControls with a
namespace of CustomControls, I've also called it DataGrid so mine is
CustomControls.DataGrid

<%@ Register TagPrefix="msdn" Namespace="CustomControls"
Assembly="CustomControls" %>


since the namespace is called "CustomControls" and the assembly will become
CustomControls.dll

if I do this in the HTML view

<msdn:DataGrid id="dgCustom" runat="server" AutoGenerateColumns="true">

</msdn:DataGrid>

I never get the variable to appear in the code view and I have an 'error
creating control' view in the pseudo browser window.


my question:

once you actually subclass a datagrid, how do you use your own subclass on
an .aspx page? (I referenced the component from the toolbox and still I can't
drag and drop it), I don't think the problem is anything as trivial as a
missing Using or the Dll not being referenced inside the web project...those
are both correctly set up

Regards and thanks in advance,
CharlesA
 
Ad

Advertisements

G

Guest

Couple of things come to mind here:

First, it's probably not a good idea to name a custom control derived from
Datagrid as "DataGrid" - too much chance for ambiguous reference errors to
pop up. Better to call it "CustomDataGrid" or "DataGridEx".

Next, in order for a control to be able to show up in the designer surface
it needs to have a <ToolboxData ...> directive. Do you have this?

Hope that helps.
Peter
 
Ad

Advertisements

G

Guest

I completeley agree Peter re the naming, I argued the very same point with a
colleague and backed down...

this is the declaration I had at the top
namespace CustomControls
{
[ToolboxData("<{0}:DataGrid runat=server ></{0}:DataGrid>")]
public class DataGrid : System.Web.UI.WebControls.DataGrid
{
protected override void Render(HtmlTextWriter output)
{

Cheers
CharlesA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top