you don't need to use DataSource to add a row, for example,              Table t = (Table)MyDataGrid.Controls[0];
    DataGridItem tr = new DataGridItem(0,0,ListItemType.Item); 
    for (int i=0; i < MyDataGrid.Items[0].Cells.Count; i++)
    {
             TableCell tc = new TableCell();
             tc.Text = "....";  
             tr.Cells.Add(tc);
    }            t.Rows.AddAt(n+1, tr);

解决方案 »

  1.   

    To saucer(思归, MS .NET MVP) :
       Thanks so much for ur help,I do appreciate it.I'll try it later.TY again.
      

  2.   

    为何,用VB。NET写的会怎么少呢
      

  3.   

    请问下,你是如何取得DataGrid控件中新增的行的所有数据??(在Button按钮的事件中)
      

  4.   

    不好意思,忘了说明了,我用的语言是C#.
    ---------------------------------------------------------------------------------
    To saucer(思归, MS .NET MVP):
    ---------------------------------------------------------------------------------
    我想是我没有表达清楚,用你的方法是能插入新行,一点问题都没有,但现在的问题在于插入的新行中显示了所有的列,而我只要在我点击的按纽下面新增一行,这里面只有一列(因为“发送内容”项内容较长,如再加上上面的那些列的话就不够显示了。)。如何实现上述功能?请继续指教,谢谢!
      

  5.   

    Table t = (Table)MyDataGrid.Controls[0];
        DataGridItem tr = new DataGridItem(0,0,ListItemType.Item); 
                 TableCell tc = new TableCell();
                 tc.ColumnSpan = MyDataGrid.Items[0].Cells.Count;            tc.Text = "....";  
                tr.Cells.Add(tc);
      
                t.Rows.AddAt(n+1, tr);
      

  6.   

    to  saucer(思归, MS .NET MVP) :
    谢谢,可以了,麻烦再请问一下,你是如何知道可以用TableCell的这个属性的呢?也就是说,如果再遇到类似的问题,是不是可以在MSDN中的什么地方或是其他地方去找呢?
      

  7.   

    hehe, because System.Web.UI.WebControls.DataGridItem is derived from System.Web.UI.WebControls.TableRow
      

  8.   

    To saucer(思归, MS .NET MVP) :
        Thanks for ur help!