在你绑定到datagrid的代码种为datatable添加新行啊!
ds是你定义的
DataTable dt=ds.Tables["你的表名"];
DataRow newrow=dt.NewRow();
...
DataGrid1.DataSource=dt.DefaultView;

解决方案 »

  1.   

    在数据源DataTable中加入一行,然后再跟datagrid绑定,datagrid是不能直接增加Item的
      

  2.   

    If Session("dw") Is Nothing Then
                Dim da As New OleDbDataAdapter("select * from log", cnn)
                Dim ds As New DataSet()
                da.Fill(ds, "employees")
                Dim tb As DataTable = New DataTable()
                tb = ds.Tables(0)
                Dim dr As DataRow = tb.NewRow            dr(1) = ds.Tables(0).Rows(0).Item(1).ToString
                dr(2) = ds.Tables(0).Rows(0).Item(2).ToString
                dr(3) = ds.Tables(0).Rows(0).Item(3).ToString            tb.Rows.Add(dr)
                Dim dw As DataView = New DataView(tb)            DataGrid1.DataSource = dw
                DataGrid1.DataBind()
                Session("dw") = dw
            Else
                Dim dw As DataView = New DataView()
                dw = Session("dw")
                Dim tb As DataTable = New DataTable()
                tb = dw.Table
                Dim dr As DataRow = tb.NewRow            dr(1) = dw.Table.Rows(0).Item(1).ToString
                dr(2) = dw.Table.Rows(0).Item(2).ToString
                dr(3) = dw.Table.Rows(0).Item(3).ToString            tb.Rows.Add(dr)            DataGrid1.DataSource = dw
                DataGrid1.DataBind()
                Session("dw") = dw
            End If
      

  3.   

    还是无法解决~~~~
    我的窗体上本来就有一个datagrid,而且不是动态产生的,也已经从数据源绑定过了,
    现在我不想把数据直接保存到数据库里面,想先在datagrid里面手写进去,像是缓存一样,最后一块写入数据库,谢谢~~~~~~~~~````
      

  4.   

    DataSet dsTemp=new DataSet();
    ....
    while(dsTemp.Tables[0].Rows.Count<6)
    {
    DataRow dr;
    dr=dsTemp.Tables[0].NewRow();
    dsTemp.Tables[0].Rows.InsertAt(dr,(dsTemp.Tables[0].Rows.Count));
    }
    dgd.DataSource=dsTemp;
    dgd.DataBind();
    //以上代码是当datagrid行少于6行时,增加到6行,如果只增加一行,就把while改成if