tags:

views:

386

answers:

2

How can I bind data to a System.Web.UI.WebControls.Table - control?

and,

How can I populate it from a List?

+2  A: 

You'd probably be better off using a repeater control for what you're looking for. You can define a <table> in the header and a </table> in the footer and just <tr><td></td></tr> in each item. You can bind from a list in that case.

Jon
+1  A: 

You can't bind to a Table webcontrol. If you want to have full control over your HTML you can either use a Repeater (like Jon mentions) or, in ASP.NET 3.0 can you can use the ListView control. The latter has a Table template available from Visual Studio. Of course, you could also use the GridView control, which renders as a table. It's probably the easiest to bind data to, but you have a little less control over the rendered output.

To populate it from a List (I presume you mean List?) it simple, you either use an ObjectDataSource or bind it manually eg.

List<MyData> list = DAL.GetList();
MyControl.DataSource = list;
MyControl.DataBind();

Where "MyControl" is the ID of the control you are binding to and "list" is the List (or other enumerable data source) that you wish to bind.

Dan Diplo