日期:2014-05-17  浏览次数:20506 次

求DataGrid数据处理方法
比如我要新增一条数据,如何将数据直接保存在DataGrid控件中,而不用保存到数据库。

------解决方案--------------------
先保存在Dataset中,然后将dataset绑定到控件中
------解决方案--------------------
refer:
DataTable dt = new DataTable();
dt.Columns.Add("column1",typeof(string));
dt.Columns.Add("column2",typeof(string));
dt.Columns.Add("column3",typeof(string));

DataRow dr = null;
dr = dt.NewRow();
dr["column1"]=textbox.Text.Split(',')[0];
dr["column2"]=textbox.Text.Split(',')[1];
dr["column3"]=textbox.Text.Split(',')[2];
dt.Rows.Add(dr);//这里新增加了一条

this.DataGird.DataSource=dt;
this.DataGrid.DataBind(); //绑定即可