在GridView中添加一行(新行) 如统计信息等

来源:互联网 发布:金融大数据服务商 编辑:程序博客网 时间:2024/05/02 01:17
  1.  DataSet ds = null;
  2.             string sql = "select * from test";
  3.             using (DBManage db = new DBManage())
  4.             {
  5.                  ds = db.GetDataSet(sql);
  6.                  DataColumn[] dc_arr = new DataColumn[] { ds.Tables[0].Columns["id"] };
  7.                  ds.Tables[0].PrimaryKey = dc_arr;
  8.                  DataRow _dr = ds.Tables[0].NewRow();
  9.                  DataRow[] _dr_sum = ds.Tables[0].Select("id='1'");
  10.                  if (_dr_sum.Length > 0)
  11.                  {
  12.                      _dr["id"] = "12";
  13.                      _dr["t_name"] = "Totals:";
  14.                      _dr["t_price"] = "0.00";
  15.                      ds.Tables[0].Rows.Add(_dr);
  16.                     //ds.Tables[0].Rows.InsertAt(_dr2, i);
                                    //i++;
  17.                  }
  18.              GridView1.DataSource = ds.Tables[0].DefaultView;
  19.              GridView1.DataBind();
  20.           }
原创粉丝点击