user1796141
user1796141

Reputation: 115

C# Custom control - class hierarchy and markup

I am trying to create the custom grid control from the scratch. So I have created the class library project for it and started with

public class ServerControl1 : WebControl
{
}

Now, I have added this reference in my project. So in my aspx page it shows something like

<cc1:ServerControl1 runat="server" id="grid1" />

Now i want to defined the columns of this grid and also want to make it familier like asp gridview

<asp:GridView ....>
    <Columns>
          <TemplateFields>
 .....

Now to make such hierarchical structure GridView >> Columns >> TemplateFields, what class structure should I implement?

I am not much in to OOPS so any help will be much appreciated. I don't want to inherit the GridView control in my class as I am not going to use it and I don't know what over burden it will bring to my control.

Upvotes: 0

Views: 179

Answers (1)

Guru Kara
Guru Kara

Reputation: 6462

Check this link with a answer already posted. Create custom control with nested tag like GridView >> Columns >> Paging

Basically what you need is not Custom control but a composite control which should implement CompositeControl, IScriptControl IScriptcontrol is optional if you need AJAX support.

And then all your properties you will be able assign values in markup. Here is a MSDN link to create one as well.

http://msdn.microsoft.com/en-us/library/12yydcke.aspx

Also you have to understand how to override CreateChildControls method in CompositeControl and how to create your control Hirearchy.

Frankly, there is quiet a bit of learning to do actually.

Upvotes: 1

Related Questions