我想在Datatable绑定GridView之前,删除一些不显示的数据,怎么写?

解决方案 »

  1.   


    DataTable newtable = set.Tables[0];
            try
            {
                //这是过滤的条件
                foreach (DataRow dataRow in newtable.Rows)
                {
                    if (((string)dataRow["ISPRIME"] == "1") && ((string)dataRow["ISLOCK"] == "0") && ((string)dataRow["ISTOP"] == "0"))
                    {
                    }
                    else
                    {
                        dataRow.Delete();
                    }
                }
                //清除DS中所有的表
                set.Tables.Clear();
                //把新表newtable加到DATASET中
                set.Tables.Add(newtable);
                //把GridView1的数据源清空
                GridView1.DataSource = null;
                //把新表newtable赋给GridView1的数据源
                GridView1.DataSource = set;
                //把新表newtable与GridView1数据绑定
                GridView1.DataBind();
    随便写的一个
      

  2.   

    筛选一下
    DataRow[] dr = DataTable.Select("你要筛选的条件");gridview.datasource = dr;
      

  3.   

    为什么不直接在sql里将数据去除掉呢?
      

  4.   

    DataView dv = new DataView(dt);
    dv.RowFilter = "UserType=1";dataGrid.DataSource = dv;
    dataGrid.DataBind();
      

  5.   

    DataRow[]   drs   =   DataTabl1.Select("id=2   or   id=4");   
      for(   int   i=0   ;   i<drs.Count   ;   i++   )   
      {   
          DataTable1.Rows.Remove(   drs[i]   );   
      
      

  6.   

    你是想删除还是想过滤?删除:
    datatable.Rows.Remove()或RemoveAt()
      

  7.   

    UP,LZ应该就是这个意思,进行判断,然后根据索引RemoveAt()删除指定项
      

  8.   

    上面有很多思路了,自己去实现吧,也就是重新把需要的数据在datatable里面绑定一下
      

  9.   

    过滤
    DataView dv = new DataView(dt); 
    dv.RowFilter = "UserType=1"; dataGrid.DataSource = dv; 
    dataGrid.DataBind(); 删除: 
    datatable.Rows.Remove()或RemoveAt()
    别忘了
    datatable.AcceptChanges();