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

  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.           }

你可能感兴趣的:(技术类)