DataTable添加行和列数据

protected void Page_Load()
    {
        DataTable newdtb = new DataTable();
        newdtb.Columns.Add("Id", typeof(int));
        newdtb.Columns.Add("ProName", typeof(string));
        newdtb.Columns.Add("ProPrice", typeof(decimal));
        newdtb.Columns["Id"].AutoIncrement = true;

for (int i = 1; i < 11; i++)
        {
            DataRow newRow = newdtb.NewRow();
            newRow["ProName"] = "pro" + i.ToString();
            newRow["ProPrice"] = 12.3m;
            newdtb.Rows.Add(newRow);       
        }
        GridView1.DataSource = newdtb;
        GridView1.DataBind();
    }

 

posted on 2013-09-17 08:10  小东北  阅读(3506)  评论(1编辑  收藏  举报