473,586 Members | 2,854 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding TemplateColumns to a GridView

All,

I am attempting to use the following code to add a TemplateColumn
to my GridView programatically :

lobj_TemplateCo lumn = New TemplateColumn
lobj_TemplateCo lumn.HeaderText =
lobj_Standard_V alues_Fields_Da taRow.Header_Te xt
lobj_TemplateCo lumn.ItemTempla te = New
GridViewTemplat e( _

CType(CType(lob j_Standard_Valu es_Fields_DataR ow.Column_Type, Integer),
eControlType), _
ListItemType.It em,
lobj_Standard_V alues_Fields_Da taRow.Database_ Field_Name, _
lobj_Standard_V alues_Fields_Da taRow.Column_Le ngth,
_

CType(CType(lob j_Standard_Valu es_Fields_DataR ow.DataType, Integer),
ValidationDataT ype), _
CType(lobj_Stan dard_Values_Fie lds_DataRow.Req uired,
Boolean))

lobj_TemplateCo lumn.EditItemTe mplate = New
GridViewTemplat e( _

CType(CType(lob j_Standard_Valu es_Fields_DataR ow.Column_Type, Integer),
eControlType), _
ListItemType.Ed itItem,
lobj_Standard_V alues_Fields_Da taRow.Database_ Field_Name, _
lobj_Standard_V alues_Fields_Da taRow.Column_Le ngth,
_

CType(CType(lob j_Standard_Valu es_Fields_DataR ow.DataType, Integer),
ValidationDataT ype), _
CType(lobj_Stan dard_Values_Fie lds_DataRow.Req uired,
Boolean))

lobj_TemplateCo lumn.FooterTemp late = New
GridViewTemplat e( _

CType(CType(lob j_Standard_Valu es_Fields_DataR ow.Column_Type, Integer),
eControlType), _
ListItemType.Fo oter,
lobj_Standard_V alues_Fields_Da taRow.Database_ Field_Name, _
lobj_Standard_V alues_Fields_Da taRow.Column_Le ngth,
_

CType(CType(lob j_Standard_Valu es_Fields_DataR ow.DataType, Integer),
ValidationDataT ype), _
CType(lobj_Stan dard_Values_Fie lds_DataRow.Req uired,
Boolean))
gvstandardtable s.Columns.Add(l obj_TemplateCol umn)

The GridViewTemplat e object is simply a class that will create the
template with the controls I desire inside of it.

The problem is that I get an error on the
......Columns.A dd(lobj_Templat eColumn).

The Error is:
Value of type 'System.Web.UI. WebControls.Tem plateColumn' cannot be
converted to 'System.Web.UI. WebControls.Dat aControlField'.

Any Ideas?

Mar 30 '06 #1
2 3563

http://www.webswapp.com/codesamples/...e/default.aspx
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"GC*****@aol.co m" wrote:
All,

I am attempting to use the following code to add a TemplateColumn
to my GridView programatically :

lobj_TemplateCo lumn = New TemplateColumn
lobj_TemplateCo lumn.HeaderText =
lobj_Standard_V alues_Fields_Da taRow.Header_Te xt
lobj_TemplateCo lumn.ItemTempla te = New
GridViewTemplat e( _

CType(CType(lob j_Standard_Valu es_Fields_DataR ow.Column_Type, Integer),
eControlType), _
ListItemType.It em,
lobj_Standard_V alues_Fields_Da taRow.Database_ Field_Name, _
lobj_Standard_V alues_Fields_Da taRow.Column_Le ngth,
_

CType(CType(lob j_Standard_Valu es_Fields_DataR ow.DataType, Integer),
ValidationDataT ype), _
CType(lobj_Stan dard_Values_Fie lds_DataRow.Req uired,
Boolean))

lobj_TemplateCo lumn.EditItemTe mplate = New
GridViewTemplat e( _

CType(CType(lob j_Standard_Valu es_Fields_DataR ow.Column_Type, Integer),
eControlType), _
ListItemType.Ed itItem,
lobj_Standard_V alues_Fields_Da taRow.Database_ Field_Name, _
lobj_Standard_V alues_Fields_Da taRow.Column_Le ngth,
_

CType(CType(lob j_Standard_Valu es_Fields_DataR ow.DataType, Integer),
ValidationDataT ype), _
CType(lobj_Stan dard_Values_Fie lds_DataRow.Req uired,
Boolean))

lobj_TemplateCo lumn.FooterTemp late = New
GridViewTemplat e( _

CType(CType(lob j_Standard_Valu es_Fields_DataR ow.Column_Type, Integer),
eControlType), _
ListItemType.Fo oter,
lobj_Standard_V alues_Fields_Da taRow.Database_ Field_Name, _
lobj_Standard_V alues_Fields_Da taRow.Column_Le ngth,
_

CType(CType(lob j_Standard_Valu es_Fields_DataR ow.DataType, Integer),
ValidationDataT ype), _
CType(lobj_Stan dard_Values_Fie lds_DataRow.Req uired,
Boolean))
gvstandardtable s.Columns.Add(l obj_TemplateCol umn)

The GridViewTemplat e object is simply a class that will create the
template with the controls I desire inside of it.

The problem is that I get an error on the
......Columns.A dd(lobj_Templat eColumn).

The Error is:
Value of type 'System.Web.UI. WebControls.Tem plateColumn' cannot be
converted to 'System.Web.UI. WebControls.Dat aControlField'.

Any Ideas?

Mar 30 '06 #2
Template columns are for a DataGrid object, GridViews use TemplateField
objects, which you add to the Columns collection.

Like this: GridView.Column s.Add(TemplateF ield);
"GC*****@aol.co m" wrote:
All,

I am attempting to use the following code to add a TemplateColumn
to my GridView programatically :

lobj_TemplateCo lumn = New TemplateColumn
lobj_TemplateCo lumn.HeaderText =
lobj_Standard_V alues_Fields_Da taRow.Header_Te xt
lobj_TemplateCo lumn.ItemTempla te = New
GridViewTemplat e( _

CType(CType(lob j_Standard_Valu es_Fields_DataR ow.Column_Type, Integer),
eControlType), _
ListItemType.It em,
lobj_Standard_V alues_Fields_Da taRow.Database_ Field_Name, _
lobj_Standard_V alues_Fields_Da taRow.Column_Le ngth,
_

CType(CType(lob j_Standard_Valu es_Fields_DataR ow.DataType, Integer),
ValidationDataT ype), _
CType(lobj_Stan dard_Values_Fie lds_DataRow.Req uired,
Boolean))

lobj_TemplateCo lumn.EditItemTe mplate = New
GridViewTemplat e( _

CType(CType(lob j_Standard_Valu es_Fields_DataR ow.Column_Type, Integer),
eControlType), _
ListItemType.Ed itItem,
lobj_Standard_V alues_Fields_Da taRow.Database_ Field_Name, _
lobj_Standard_V alues_Fields_Da taRow.Column_Le ngth,
_

CType(CType(lob j_Standard_Valu es_Fields_DataR ow.DataType, Integer),
ValidationDataT ype), _
CType(lobj_Stan dard_Values_Fie lds_DataRow.Req uired,
Boolean))

lobj_TemplateCo lumn.FooterTemp late = New
GridViewTemplat e( _

CType(CType(lob j_Standard_Valu es_Fields_DataR ow.Column_Type, Integer),
eControlType), _
ListItemType.Fo oter,
lobj_Standard_V alues_Fields_Da taRow.Database_ Field_Name, _
lobj_Standard_V alues_Fields_Da taRow.Column_Le ngth,
_

CType(CType(lob j_Standard_Valu es_Fields_DataR ow.DataType, Integer),
ValidationDataT ype), _
CType(lobj_Stan dard_Values_Fie lds_DataRow.Req uired,
Boolean))
gvstandardtable s.Columns.Add(l obj_TemplateCol umn)

The GridViewTemplat e object is simply a class that will create the
template with the controls I desire inside of it.

The problem is that I get an error on the
......Columns.A dd(lobj_Templat eColumn).

The Error is:
Value of type 'System.Web.UI. WebControls.Tem plateColumn' cannot be
converted to 'System.Web.UI. WebControls.Dat aControlField'.

Any Ideas?

Mar 30 '06 #3

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

Similar topics

2
3624
by: Clayton Hamilton | last post by:
I have a DataGrid on a webform bound to a Datasource and can successfully use <ItemTemplate> to create edit/update/cancel functionality for user maintenance of data. I use separate logic to delete a row. Everything works just fine. BUT I would like to add a button to (for example) the DataGrid header, which when pressed will add a new...
3
2630
by: Jeremy Chapman | last post by:
At run time I've added a TemplateColumn to a DataGrid. Now I'm trying to add a Table control to the TemplateColumns's HeaderTemplate and ItemTemplate. In essence, I'm trying to do in code, the equilavent of this html: <asp:TemplateColumn> <HeaderTemplate>
1
985
by: Tim::.. | last post by:
Hi can someone tell me how I get the values from a datagrid using template columns??? I tried like this but I keep getting Input string was not in a correct format. I don't think I'm doing this the correct why when it comes to using templatecolumns can someone please HELP! Thanks! ...:: CODE Dim pageID As Integer =...
4
8743
by: VMI | last post by:
I'm working on a questionaire, and I'd like to add the questions to a gridview, so that each row (of two "columns" each) has the question in one field, and the editable section (where the user will enter the answer) in the next field. The questions are not stored in a table, and I'm thinking of saving the answers manually (i.e. no...
0
1319
by: ami | last post by:
Hi everyone, I have a question about dynamically adding columns to a gridview. Based on user input (after a button click), some columns are being added to my gridview. What I do: OnButtonClick: I call a method that adds the new boundfield
1
5021
by: Dev147 | last post by:
I need to dynamically create a GridView that contains a variable number of columns that must be bound to an underlying collection in an entity class. These columns represent days from a specified Start Date to a specified End Date. For eg. if the user selects 01/09 and 04/09, 4 columns need to be added to the GridView. My GridView is bound...
0
1959
by: ganesh22 | last post by:
Hi... Iam using GridView in asp.net(2.0) .My requirement is user can add,update,delete in gridview I written the code for add & update but can u help adding rows in grid view My code: <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="3" Height="237px" Style="z-index: 100; left: 155px; ...
2
3107
by: Kbalz | last post by:
I have a user control that has a gridview in it. I am dynamically setting up its datasource and columns based on an XML file. I have everything done except adding columns to the gridview, so that the user only sees certain columns based on the XML file. In my ASCX page I simply defined the gridview <asp:GridView ID="gvSearchResults"...
7
6189
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
I'm adding subheadings to a gridview. Each sub head has a few link buttons. I'm adding the controls in the rowdatabound event code follows: sorry about the length here. I have to be missing something. The buttons show up and post back, but the events do not fire. any help would be appreciated!!! Thank you. protected void...
0
7911
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...
0
8200
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
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...
1
5710
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...
0
5390
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...
0
3864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1448
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1179
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...

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.