views:

36

answers:

2

I have a gridview that I would like to be able to bind to several sqldatasources, but still use template fields. Each datasource is different and would have different columns so I'm not sure how to go about this. Is it possible to define a set of template fields or overlying template per datasource?

A: 

Personally with this it would sound more appropriate to have a separate datagrid control for each one.

Mitchel Sellers
+1  A: 

The one way I can think of to do this would be to populate the GridView with rows dynamically from you datasources and then use the OnRowCreated event to switch the fields you want into template fields.

You can either extend the ITemplate interface or you can use a custom ascx control to load into the field like so.

TemplateColumn bc = new TemplateColumn();
bc.HeaderText = "Template Column";
bc.ItemTemplate = Page.LoadTemplate(TEMPLATEFILE);
grid.Columns.Add(bc);

Here are a few good links to help you out if you decide to take this road, really you may get better performance (and less maintainability headaches) from separating them out. Even update panels based on user input would be fine.

Link 1 Link 2

If you want to change your approach and your not sure about which option will suit you best try posting a bit more background about your project and we can go from there. Happy Coding!

JonVD