所以要转换一下才能绑定,把二给数组转换为DataTable或者使用item.insert()方法添加;
把二组数组转换为DataTable进行绑定:
DataTable dt = new DataTable("tbl");
dt.columns.add("0", Typeof(System.string));
dt.columns.add("1", Typeof(System.string));
DataRow row;
for(int i=0; i< aa.length; i++)
{
row = dt.newrow();
row["0"] = aa[i,0];
row["1"] = aa[i,1];
dt.row.add(row);
}
DropDownList1.DataSource=dt;
DropDownList1.DataTextField="0";
DropDownList1.DataValueField="1";
DropDownList1.DataBind();
dt.columns.add("0", Typeof(System.string));
dt.columns.add("1", Typeof(System.string));
DataRow row;
for(int i=0; i< aa.length; i++)
{
row = dt.newrow();
row["0"] = aa[i,0];
row["1"] = aa[i,1];
dt.row.add(row);
}
DropDownList1.DataSource=dt;
DropDownList1.DataTextField="0";
DropDownList1.DataValueField="1";
DropDownList1.DataBind();
使用item.insert()方法添加:
for(int j=0;j<aa.GetLength(0);j++)
{
ddl.Items.Add(new ListItem(aa[j,0],aa[j,1]));
}
{
ddl.Items.Add(new ListItem(aa[j,0],aa[j,1]));
}