473,396 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Create TemplateColumn on datagrid exclusively with code behind

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
Nov 19 '05 #1
2 2110
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


Nov 19 '05 #2
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 <ba****@NOSPAMdevelop.com> wrote in message news:<42**********************@msnews.microsoft.co m>...

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

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dave | last post by:
Hello. Can anybody explain me how to use TemplateColumn?
0
by: Tigrou | last post by:
Hello, I'm searching for a solution who permit me to create an TemplateColumn in a DataGrid into codebehind... I found only solution for create it into the ASPX code... My problem is to find...
2
by: Tigrou | last post by:
Hello, I'm searching for a solution who permit me to create an TemplateColumn in a DataGrid into codebehind... I found only solution for create it into the ASPX code... My problem is to find...
2
by: Jim Bancroft | last post by:
Hi everyone, I have a couple of TemplateColumns in my DataGrid that I need to hide from view....yet still have their contents available in the code-behind file. My HTML code looks like this at...
1
by: Shapper | last post by:
Hello, How to create a Template Column with an Image in a datagrid from my VB code? Thanks, Miguel
4
by: matt | last post by:
hello, i have a datagrid w/ a TemplateColumn in it, like so: <asp:TemplateColumn HeaderText="Select"> <ItemTemplate> <asp:CheckBox ID="chkSelected" Runat="server"/> </ItemTemplate>...
0
by: Vagabond Software | last post by:
I am fairly new to ASP.NET, so bear with me... I have a Datagrid with a data-bound DropDownList in the TemplateColumn. Here is the HTML code: <asp:TemplateColumn HeaderText="Void"> <ItemStyle...
3
by: rn5a | last post by:
A DataGrid has the following TemplateColumn: <asp:DataGrid ID="dgCart"...OnSortCommand="SortGrid" AllowSorting="true"....> <Column> <asp:TemplateColumn HeaderImageUrl="Images\Up.gif"...
2
by: =?Utf-8?B?RXVnZW5l?= | last post by:
Hi, I use a datagrid with asp:templatecolumn, and handles the datagrid's ItemDataBound event, whereby I assign a value to this asp:templatecolumn text. e.Item.Cells.Text = e.Item.Cells.Text +...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.