gridview动态添加行(不用datatable实现)

GridViewRow newrow = new GridViewRow(0, 0, DataControlRowType.Separator, DataControlRowState.Normal); 
TableCell[] tc=new TableCell[5];
                    for (int i = 0; i < 5; i++)
                    {
                        tc[i] = new TableCell();
                    }
                    tc[0].Text = (GridView1.Rows.Count + 1).ToString();
                    tc[1].Text = "第一列内容";
                    tc[2].Text = "第二列内容";
                    tc[3].Text = "第三列内容";
                    tc[4].Text = "第四列内容";
                    tc[5].Text = "第五列内容";
                    newrow.Cells.AddRange(tc);
                    GridView1.Controls[0].Controls.AddAt(GridView1.Rows.Count + 1, newrow); 

 

posted @ 2016-08-20 09:28  老菜鸟瞎叨叨  阅读(1072)  评论(0)    收藏  举报