首页上一页 1 下一页尾页 1 条记录 1/1页
将二维数组添加到一个表绑定到Gridview
发表在ASP.NET图书答疑
2009-10-31
是否精华
是
否
版块置顶:
是
否
DataSet ds = new DataSet("dsname");
DataTable table2 = new DataTable("tb2");
string[,] arr2 = new string[2, 3] { { "aa", "bb", "cc" }, { "aaa", "bbb", "ccc" } };
for (int i = 0; i < arr2 .Rank ;i++ )
{
TableRow r = new TableRow();
for (int j = 0; j <= arr2.GetUpperBound (arr2 .Rank -1);j++ )
{
TableCell c = new TableCell();
c.Text = arr2[i,j];
r.Cells.Add(c);
}
table2.Rows.Add(r);
}
ds.Tables.Add(table2 );
GridView1.DataSource = ds.Tables["tb2"].DefaultView;
GridView1.DataBind();
运行后Gridview中显示的结果竟然是这样的:
System.Web.UI.WebControls.TableRow 空白 空白
System.Web.UI.WebControls.TableRow 空白 空白
DataTable table2 = new DataTable("tb2");
string[,] arr2 = new string[2, 3] { { "aa", "bb", "cc" }, { "aaa", "bbb", "ccc" } };
for (int i = 0; i < arr2 .Rank ;i++ )
{
TableRow r = new TableRow();
for (int j = 0; j <= arr2.GetUpperBound (arr2 .Rank -1);j++ )
{
TableCell c = new TableCell();
c.Text = arr2[i,j];
r.Cells.Add(c);
}
table2.Rows.Add(r);
}
ds.Tables.Add(table2 );
GridView1.DataSource = ds.Tables["tb2"].DefaultView;
GridView1.DataBind();
运行后Gridview中显示的结果竟然是这样的:
System.Web.UI.WebControls.TableRow 空白 空白
System.Web.UI.WebControls.TableRow 空白 空白