Here is the way to add a template column to GridView dynamically (runtime):

TemplateField tf = new TemplateField();
tf.HeaderText = "NewTemplate column";
MyTemplate template = new MyTemplate("test");
tf.ItemTemplate = template;
GridView1.Columns.Clear();
GridView1.Columns.Add(tf);

string[] s = { “as”, “34″, “z”, “@#4″, “666″ };
GridView1.DataSource = s;
GridView1.DataBind();

VN:F [1.1.6_502]
Rating: 3.3/5 (3 votes cast)
Share:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • DotNetKicks
  • LinkedIn
  • Live
  • MySpace
  • StumbleUpon
  • Technorati

Related posts:

  1. How to access items in a GridView?
  2. Build DateTime from values
  3. Reorder listbox items with JavaScript and ASP.NET
  4. Extreme beginner’s LINQ sample in VB.NET
  5. How to dynamically make an InfoPath form