473,804 Members | 2,296 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Colum ns.Add(tc)

Any ideas?

Thanks
Ricardo
Nov 19 '05 #1
2 2124
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.Colum ns.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****@NOSPAMd evelop.com> wrote in message news:<42******* *************** @msnews.microso ft.com>...

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
1524
by: Dave | last post by:
Hello. Can anybody explain me how to use TemplateColumn?
0
1239
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 a solution for add ImageButton controls into this column, for now my code is: Dim colSupp As New TemplateColumn
2
3126
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 a solution for add ImageButton controls into this column, for now my code is: Dim colSupp As New TemplateColumn
2
1558
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 the moment: <asp:TemplateColumn> <ItemTemplate> <input type="hidden" runat="server" id="FieldID" value='<%#DataBinder.Eval(Container.DataItem, "myField")%>'>
1
1300
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
2751
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> </asp:TemplateColumn>
0
1176
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 horizontalalign="Left" wrap="False"></ItemStyle> <ItemTemplate> <%#Databinder.Eval(Container.DataItem, "isVoid")%> </ItemTemplate>
3
7384
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" HeaderText="ID" SortExpression="PID"> <ItemTemplate> <asp:Label ID="lblPID" Text=<%# Container.DataItem("PID") %> runat="server"/>
2
3286
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 + e.Item.Cells.Text; /* column index 2 and 3 are boundcolumn */ The issue that I have is that the column header (index 1) would be blank after it.
0
9714
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10346
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10347
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7635
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6863
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5531
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3832
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.