Composite Web Custom Control derived from DataGrid

S

SRGTech_Max

Hello

I am a beginner at creating composite web controls. What I am trying to do
it add functionality to the DataGrid webcontrol by adding two dropdowns, a
textbox and two buttons to it (for search-capabilities)

I have created a new class (DataGridFilter) derived from DataGrid

e.g. public class DataGridFilter : DataGrid, INamingContainer{}

I have overriden the CreateChildControls method and added the new controls
(dropdowns, textbox, etc.) to the Controls collection

e.g.
DropDownList ddlColumnNames = new DropDownList();
Controls.Add(ddlColumnNames);

When I test the control (bind it with data on a webform), the only output i
get is the datagrid. It doesn't keep/draw all the controls I have created in
the CreateChildControls function.

What am I doing wrong? (I shouldn't have to mess with the Render method
since this is a composite web custom control, right?)

Let me know if you need to see more code. Any help is appreciated.

Thanks
 
R

recoil

#1 - Make sure that the CreateChildControls is actually executing.
Honestly I prefer doing this in the OnInit event but that is just me.

#2 - debug the application in the Render method and check your
Control's Control Collection, making sure that the controls are still
added. It could be possible that at some point the DataGrid decides to
clean out any extra child controls. If this is the case then this means
that you would have to readd the items or create a container control
that renders your controls and then the data grid.
 
S

SRGTech_Max

It seems that if I derive my class from any existing webcontrols (eg.
DataGrid), then I have to override the prerender method to add controls to
the base class's controls. But i also noticed that I can only place controls
AFTER the base class's controls have been rendered (if i place the controls
BEFORE the base class's controls are rendered, then it won't render the base
control; in this case the datagrid)

All i want to do is add a textbox, filter and clear buttons BEFORE the
datagrid...

Thanks for your help though :)
 

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

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top