How to add TemplateField created in .aspx markup to GridView column in code behind?

Vijit

New Member
Basically, I want a button that adds a new column with my controls (i.e. TextBox, DropDownList) to my GridView.Already seems simple enough with this:\[code\]protected void btn_AddColumn_Click(object sender, EventArgs e){ TemplateField MyTemplateField = new TemplateField(); gv_SupplierPrices.Columns.Add(MyTemplateField);}\[/code\]Say I want to add this markup:\[code\]<asp:TemplateField> <ItemTemplate> <table style="width:100%;"> <tr> <td><asp:TextBox ID="tbox_ItemPrice" runat="server"></asp:TextBox></td> </tr> </table> </ItemTemplate></asp:TemplateField>\[/code\]Here's the problem. How do I use a TemplateField I created in markup on my .aspx page and add it to my new column on code behind? I don't know and don't want to create my TemplateField on code behind because I will not be able to create elaborate or fancy markups. They will just look like controls that are next to each other. It's very ugly.P.S. If anyone is curious as to what I'm actually making, I'm basically turning my GridView into an Excel-like gridsheet. New columns represent a supplier and each row represents an item the supplier is selling. They want it that way because it's easier to compare prices side-by-side whilst they're filling it up.
 
Back
Top