gridview默认出来的不就是table啊。只不过前面会多一个标签div/span就是了。
如果你想把div/span标签去掉。你可以继承GridView覆盖Render用base.RenderContents(writer);
1 /// <summary>
2 /// 输出DataTable
3 /// </summary>
4 /// <param name="OutDataTable">DataTable</param>
5 /// <returns></returns>
6 public static string Table(System.Data.DataTable OutDataTable)
7 {
8 string outs = "<table border='1' cellpadding='0' cellspacing='0' bordercolor='#CCCCCC'>";
9 int rows = OutDataTable.Rows.Count;
10 int columns = OutDataTable.Columns.Count;
11
12 for (int i = 0; i < rows; i++)
13 {
14 outs += "<tr>";
15
16 for (int m = 0; m < columns; m++)
17 {
18 outs += "<td width='20px' height='20px' align='center'>";
19 outs += OutDataTable.Rows[i][m].ToString();
20 outs += "</td>";
21 }
22
23 outs += "</tr>";
24 }
25
26 outs += "</table>";
27 return outs;
28 }
多数情况下,从数据库查询得到的是一张表(DataTable),一个简单实现绑定功能,你可以加入更多参数Table实现更多绑定选择,事实上,gridview已经做得不错了,你不满意也可以自定义模版列的嘛