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