GridView一般跟DataTable绑定,只要写个方法FillBlankRow,为DataTable添加一定数量的空行,就行了。
- C# code
-
///<summary>/// 根据期望的表大小向DataTable填充空行。 ///</summary>///<param name="dt">数据表实例。</param>///<param name="dataTableSize">期望的数据表大小。</param>publicstaticvoid FillBlankRow(DataTable dt, int dataTableSize){if (dataTableSize <0)thrownew ArgumentOutOfRangeException("方法参数dataTableSize不能是负数。");if (dt.Rows.Count < dataTableSize){int additionCount = dataTableSize - dt.Rows.Count;for (int i =0; i < additionCount; i++){DataRow row = dt.NewRow();dt.Rows.Add(row);}}}
调用:
FillBlankRow(dt,10);
GridView1.DataSource=dt;
GridView1.DataBind();