Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Create TemplateColumn on datagrid exclusively with code behind

Reply
Thread Tools

Create TemplateColumn on datagrid exclusively with code behind

 
 
Ricardo
Guest
Posts: n/a
 
      04-11-2005
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
 
Reply With Quote
 
 
 
 
Brock Allen
Guest
Posts: n/a
 
      04-11-2005
In essence the Template is just a class that knows how to do dynamically
add other controls. So you'd have to write that class. Here'a a Microsoft
example:

http://msdn.microsoft.com/library/de...ridcontrol.asp

Here's a diff example that shows some DataBinding:

http://www.c-sharpcorner.com/Code/20...ynamically.asp

One other approach is to simply have an extra column that you add controls
to yourself in the DataGrid's ItemDataBoudn event.

-Brock
DevelopMentor
http://staff.develop.com/ballen



> 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




 
Reply With Quote
 
 
 
 
David Alpert
Guest
Posts: n/a
 
      04-11-2005
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

Brock Allen <(E-Mail Removed)> wrote in message news:<(E-Mail Removed) m>...
>
> One other approach is to simply have an extra column that you add controls
> to yourself in the DataGrid's ItemDataBoudn event.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Databinding templated controls exclusively from the code behind AC [MVP MCMS] ASP .Net 4 01-04-2007 08:20 AM
Create TemplateColumn on datagrid exclusively with code behind Ricardo ASP .Net Datagrid Control 2 04-11-2005 08:33 PM
Create TemplateColumn for DataGrid in codebehind (vb.net) ? =?Utf-8?B?VGlncm91?= ASP .Net 2 11-30-2004 09:59 AM
Create a TemplateColumn for DataGrid in codebehind (vb.net) ? =?Utf-8?B?VGlncm91?= ASP .Net 0 11-27-2004 02:53 PM
Make DataGrid TemplateColumn read-only in code Bob ASP .Net 0 07-09-2003 05:56 PM



Advertisments