其实都是一样的,最后都要添加到datasource中去。
你看到的只是添加的形式不同而已!

解决方案 »

  1.   

    20分,少了一点?其实实现的方法,跟你说的一样,通外面的控件来新增。思路是在datagrid的数据源设置为一个datatable对象,在datatable中新增一行,再绑到datagrid中,并把该行设为编辑模式,提交时更新数据库就可以了。
      

  2.   

    我现在就是想不通过外界控件,而是直接在DATAGRID里的绑定控件来实现在新增.可以吗?
      

  3.   

    可以,在脚注栏上加一个button控件,作新增按钮,单击时触发按钮click事件.然后按上面的思路写代码,下面的代码示例如何在脚注栏上增加一个按钮(在datagrid的itemcreated事件中写):
    private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {

    //获得触发该事件的模板类型
    ListItemType lit_footer=e.Item.ItemType;
    //如果是脚注
    if (lit_footer==ListItemType.Footer)
    {
    //脚注是一个空行,删除单元格,剩一个单元格并使之跨越所有列
    TableCellCollection tcc_footer=e.Item.Cells;
    int int_cell_count=tcc_footer.Count;
    for (int i=0;i<int_cell_count-1;i++)
    e.Item.Cells.RemoveAt(1);
    //此时只有一个单元格,在脚注行增加一个新增按钮
    TableCell tc_footer=e.Item.Cells[0];
    tc_footer.ColumnSpan=int_cell_count;
    lb_addnew=new LinkButton();
    lb_addnew.Text="新增";
    lb_addnew.ToolTip="新增菜单";
    lb_addnew.Click += new System.EventHandler(this.lb_addnew_click);
    tc_footer.Controls.AddAt(0,lb_addnew);
    lb_delete=new LinkButton();
    }
    }