在Gridview中绑定数据无需进入数据库

时间:2016-01-06 16:57:55

标签: c# asp.net

我正在尝试通过网格视图中的任何注册表单绑定数据。 但是,他们是没有数据库。我们没有任何数据库,因此没有数据存储要检索。我怎么能这样做.. ???

1 个答案:

答案 0 :(得分:1)

    //declare a datatable
    DataTable dt = new DataTable();
    dt.Columns.Add(new DataColumn("id", typeof(int)));
    dt.Columns.Add(new DataColumn("Name", typeof(string)));

    //fill it with data
    DataRow dr = dt.NewRow();
    dr["id"] = 1;
    dr["Name"] = "Name"
    dt.Rows.Add(dr);

    //set the datasource and bind the grid view
    GridView1.DataSource = dt;
    GridView1.DataBind();