Dynamically change GridView item template

I have a fairly big asp.net website that use GridView bound to the same object in lots of places. I’m using an item template to customize each row. However to have the same template in all the pages I have to copy & paste the item template to each page. Obviously this is not the best solution. On top of this I want to be able to change the template used by the GridView, by changing some configuration file.
One option would be to create an user control with the DataGrid and expose the necessary properties to be used in each page. However this does not fulfill the second requirement to be able do dynamically change the template.
Basically I’m looking for a way to say to the GridView to use a template and be able to do this dynamically. Any idea would be helpful.

How can I re-instantiate dynamic ASP.NET user controls without using a database?

I’m currently working with a part of my application that uses Dynamic Web User Controls and I’m having a bit of trouble figuring out the best way to re-instantiate the controls on postback by using ViewState or some other method that doesn’t require me to query a database on each postback.

Persistent dynamic control in ASP.Net

<asp:Button onclick="Some_event" Text="Add TextBox" ID="id1" runat="server" /> //once clicked: <asp:TextBox ID="txt1" ……></asp:TextBox> //when clicked again: <asp:TextBox ID="txt1" ……></asp:TextBox> <asp:TextBox ID="txt2" ……></asp:TextBox> //and so on… Is there a way to create dynamic controls which will persist even after the postback? In other words, when the user clicks on the button, a new textbox will be generated … Read more

adding an event handler to a dynamically created checkbox (aspx, c#)

So my problem is that I want to add an event handler to a dynamically created CheckBox. I have already looked at other ways to do this, and decided that creating a dynamic table which contains my CheckBoxes is the best option for me. I have not added these CheckBoxes to the Control Tree because I need to manage the ViewState manually. Either way, my code works in every way except that my CheckBox’s CheckChanged Event does not fire. I am adding this eventhandler to my CheckBox in my pageLoad event, however, any page event I try seems to give me the same results: