日期:2014-05-18  浏览次数:20521 次

girdview自动生成 求教!!!!!!!!!
代码如下,克是到业面以后就是没有反映,数据库有数据。
table也是服务器控件,高手解决。谢谢。
 if (!IsPostBack)
  {
  ArrayList arrData = new ArrayList();
  ArrayList arrName = new ArrayList();
  arrData.Add("depotmove_id");
  arrData.Add("depotmove_name");
  arrName.Add("主键");
  arrName.Add("名称");
  //GridViewUI1.bind(move.SelectAll(),arrData,arrName);


  GridView grid = new GridView();
  TableRow row = new TableRow();
  TableCell cell = new TableCell();
  //grid.AutoGenerateColumns = false;
  for (int i = 0; i < arrData.Count; i++)
  {

  BoundField bound = new BoundField();
  bound.DataField = arrData[i].ToString();
  bound.HeaderText = arrName[i].ToString();
  grid.Columns.Add(bound);
  grid.DataBind();
  }
  cell.Controls.Add(grid);
  row.Cells.Add(cell);
  Table1.Rows.Add(row);
   
  }

------解决方案--------------------
protected void Page_Load(object sender, EventArgs e)
{
GridView mygriview = new GridView();
mygriview.ID = "griview1";
this.form1.Controls.Add(mygriview);
mygriview.DataSource = CreateDataSource();
mygriview.DataBind();


}

public DataView CreateDataSource()
{

DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add(new DataColumn("身份证号码", typeof(string)));
dt.Columns.Add(new DataColumn("图书单价", typeof(decimal)));
dt.Columns.Add(new DataColumn("购买数量", typeof(Int32)));
dt.Columns.Add(new DataColumn("总价格", typeof(decimal)));


for (int i = 0; i < 30; i++)
{
dr = dt.NewRow();

dr[0] = "123456789123456789";
dr[1] = 100 * i / 3.0;
dr[2] = i + 5;
dr[3] = (decimal)dr[1] * (Int32)dr[2];
dt.Rows.Add(dr);
}
DataView dv = new DataView(dt);
return dv;
}