C# 怎么给datagridview手动设置几条空数据。我有一个按钮“增加行”,点击这个按钮我的grid就每次都加7行!

这个怎么完善啊!
2024-12-23 14:01:57
推荐回答(3个)
回答1:

gridview 有点麻烦 可以用repeater
protected void btnCreate_Click(object sender, EventArgs e)
{
try
{

string name = Name.Text;

DataTable _dtPerons = buildDt(a,name,dept,date);
Repeater1.DataSource = _dtPerons;
Repeater1.DataBind();

}
catch
{

}
}

private DataTable buildDt( string name )
{
DataTable dt = new DataTable();

dt.Columns.Add(new DataColumn("name"));

for (int i = 1; i <= num; i++)
{
DataRow dr = dt.NewRow();

dr["name"] = name;

dt.Rows.Add(dr);
}
return dt;
}

回答2:

复制datagridview的行格式,并添加DataRow的实例化。

回答3:

添加新列