如何在DataGrid中增加一空白行
我是用DataView作为数据集的数据源,想在DataGrid中增加空白行
在DataView中增加一空白行,就是说本来一页要显示十行,但实际只有7行,其他三行要用空白行代替,要怎么办,
而且在数据库中有一字段是不能为空的.
这个问题困挠了我很久,还请高手们指点指点
------解决方案--------------------没注意看题不好意思哈,再来次
ds = 数据源;
DataRow oRow = ds.Tables[0].NewRow();
int i = this.GridView.Items.Count;
if(i == 0||(i%this.DataGrid.PageSize)!=0)
{
int j = this.GridView.PageSize-(i%this.GridView.PageSize);
for(int k=0;k <j;k++)
{
oRow[k] = " ";
}
ds.Tables[0].Rows.Add(oRow);
DataView dv;
dv = ds.Tables[0].DefaultView;
GridView.DataSource = dv;
GridView.DataBind();
------解决方案--------------------sorry!刚才我写的有点问题.如下程序编译通过.
protected void Page_Load(object sender, EventArgs e)
{
DataTable oDT = MakeDataTable();
this.GridView1.DataSource = oDT;
this.GridView1.DataBind();
int n = this.GridView1.Rows.Count;
DataView dv = new DataView();
for (int i = 0; i < 3; i++)
{
dv = oDT.DefaultView;
dv.AddNew();
}
this.GridView1.DataSource = dv;
this.GridView1.DataBind();
//int m = this.GridView1.Rows.Count;
}
private DataTable MakeDataTable()
{
// Create new DataTable.
DataTable table = new DataTable();
// Declare DataColumn and DataRow variables.
DataColumn column;
DataRow row;
// Create new DataColumn, set DataType, ColumnName
// and add to DataTable.
column = new DataColumn();
column.DataType = System.Type.GetType( "System.Int32 ");
column.ColumnName = "id ";
table.Columns.Add(column);
// Create second column.
column = new DataColumn();
column.DataType = Type.GetType( "System.String ");
column.ColumnName = "item ";
table.Columns.Add(column);
// Create new DataRow objects and add to DataTable.
for (int i = 0; i < 10; i++)
{
row = table.NewRow();
row[ "id "] = i;
row[ "item "] = "item " + i;
table.Rows.Add(row);
}
return table;
// Set to DataGrid.DataSource property to the table.
}