Home All Groups Group Topic Archive Search About

asp.net: Composite Control with GridView

Author
14 Jul 2005 3:18 PM
Patrick
Hello

I try to make a composite control which contains a GridView. My problem is
now, how do I add the <Columns> to this Gridview. I can do
myGridView.Columns.Add(), but it asks for a DatacontrolField, but I didn't
figure out how to create a DataControlField for the following entry:

<asp:CommandField ShowDeleteButton="True" />

<asp:BoundField DataField="UserId" HeaderText="User Id" ReadOnly="True" />

<asp:BoundField DataField="UserName" HeaderText="User Name" />



Can someone help?

Thanks

Author
18 Jul 2005 2:32 PM
Teemu Keiski
Hi,

DataControlField is just base class for GridView fields such as BoundField.
Therefore you'd need to instantiate these columns as separate objects (with
these derived  types) in code and add to the Columns collection.

What you showed was example of the declarative syntax which can be used on
aspx/ascx etc, however it doesn't apply in code. You can parse content from
markup (string) using Page.ParseControl however, it doesn't provide the same
(Intellisense etc features provided by the IDE) which you get if you
instantiate them in code.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke