473,385 Members | 2,014 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,385 software developers and data experts.

Template column

Hi,
I could add a boundcolumn to gridview using this

BoundColumn bc = new BoundColumn();
bc.DataField = "ProductsName";
bc.HeaderText = "Product";
gridview1.columns.add(bc);

What I would like to ask, how can I perform this with TemplateColumn?
I have a problem to bound template column to any object such as dropdownlist
or textbox.
TIA.
Regards,
Gun
Apr 2 '07 #1
1 1282
Hi,

To create a TemplateColumn for a grid view, you need to create a
ItemTemplate class that implements the ITemplate interface. Something like
this...

public class ItemTemplate : ITemplate
{

string ControlName = "";
object DataSource = null;
//ControlName: Name of the drop down list.
public ItemTemplate(string ControlName,object DataSource)
{
this.ControlName = ControlName;
this.DataSource = DataSource;
}
public void InstantiateIn(Control objContainer)
{
DropDownList myDDl = new DropDownList ();
myDDl .ID = this.ControlName;
myDDl.DataSource = this.DataSource;
myDDl.DataBind();

//Note: If your DropDownList need not be bound to the dataSource,
// Then you cld create the list items and add then to the drop
down list.

// In your constructor for this class, you cld remove the
DataSource
//parameter.

objContainer.Controls.Add(rdAnswer);
}

}
In the code behind of the form where you are having your grid view,
instantiate this class and add the column to the grid view:

TemplateField objTempCol = new TemplateField();

objTempCol .HeaderText = "My Template column";

ItemTemplate objTemplate = new ItemTemplate("myDropDownList", dtSource);

//dtSource is the name of the dataTable which you wish to bind.

objTempCol .ItemTemplate = objTemplate;

MyGridView.Columns.Add(objTempCol );
I hope this helps,

-Parvathy Padmanabhan
Apr 2 '07 #2

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

Similar topics

2
by: damonf | last post by:
I'm currently trying to add an ASP hyperlink to a template column in a datagrid. The normal hyperlink column doesn't give me the ability to add attributes to the item. In my grid there are four...
0
by: Michelle Stone | last post by:
i am puzzled. i have previously bound datasets to datagrids which contain the filename of IMAGES. And i use template columns to show the image for each row. But now it is not working. I have reviewed...
2
by: Patrick Delifer | last post by:
Hi, I am trying to implement a JS confirm dialog when a user is deleting something off my Datagrid. The problem is that I don't have a Delete button in which case I could write the following...
1
by: William Gower | last post by:
I need to develop a datagrid that uses columns from a table. In addition I need two columns (checkboxes) that the user will use to indicate that this record can be closed later. The checkboxed...
1
by: RN | last post by:
Hi. I used this article to add a template column to a datagrid that is entirely created with code: ...
0
by: wwcoop | last post by:
I am connected to an Access Database. I am reading a Yes/No field from the DB which translates back as True/False in the text field of my datagrid. I want to use a checkbox to show the value...
1
by: Ken Varn | last post by:
I have a problem where my DataGrid would not maintain the ViewState of my databound rows. I finally narrowed down the problem. If my first column is a template column, the view state for the...
1
by: louise raisbeck | last post by:
This sounds complicated but bear with me. I have a datagrid. It is dynamic in that, i dont know how many columns i will have until the dataset is back so i have to build the datagrid dynamically. I...
2
by: Charleees | last post by:
Hi all, I have a DataGrid with Template Columns..... There are LAbels,Linkbuttons in the Single Row.. I have to set the Constant Column width for those Template Columns in Grid... Wat...
1
by: rogerford | last post by:
I have a grid which i bind with values from Database. I have events to edit and update the grid. I am not using SqlDatasource to connect to DB. Rather i am doing the updating of the grid...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.