Create TemplateColumn on datagrid exclusively with code behind

R

Ricardo

Hi,

How can I insert a TemplateColumn on a Datagrid on the fly?

Basically I'm after how to create a TemplateColumn, add a button and a
label to its control list and add the TemplateColumn to my Datagrid.

Something like:

Dim tc as New TemplateColumn
tc.Controls.Add(New Button)
tc.Controls.Add(New Label)
DataGrid1.Columns.Add(tc)

Any ideas?

Thanks
Ricardo
 
B

Brock Allen

D

David Alpert

Or, if you can access the DataGrid's OnItemCreated() routine (possibly
there's an ItemCreated event?) you can modify each row's HTML
programmtically after it is created and before it is passed to
OnItemDataBound(). This is a great way to add dynamically created
controls (or odd patterns of rowspanned cells) and it cleanly
separates control creation from databinding.

Check out Dan Wahlin's excellent example on Extending the DataGrid...
http://www.xmlforasp.net/codeSection.aspx?csID=92

David
 

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,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top