gridView的一个增加行的问题
C# code
protected void btnAddCell_Click(object sender, EventArgs e)
{
data();
}
private void data()
{
DataTable dt = new DataTable();
DataRow row = null;
TableCell cell = new TableCell();
DataColumn field;
if (dt.Rows.Count == 0)
{
for (int i = 0; i < 5; i++)
{
Random ran = new Random();
cell = new TableCell();
field = new DataColumn();
row = dt.NewRow();
row.Table.Columns.Add(field);
}
dt.Rows.Add(row);
}
this.GridData2.DataSource = dt;
this.GridData2.DataBind();
}
我现在想点击增加行的时候就出现一行,在次点击就在这个基础上加一行,加下面。
------解决方案--------------------
private void data()
{
if(ViewState["Dt"]!=null)
{
//dt=ViewState["Dt"] as DataTable;
//NewROW()
//Row.add
//绑定
ViewState["Dt"]=dt;
}
else
{
DataTable dt = new DataTable();
DataRow row = null;
TableCell cell = new TableCell();
DataColumn field;
if (dt.Rows.Count == 0)
{
for (int i = 0; i < 5; i++)
{
Random ran = new Random();
cell = new TableCell();
field = new DataColumn();
row = dt.NewRow();
row.Table.Columns.Add(field);
}
dt.Rows.Add(row);
}
this.GridData2.DataSource = dt;
this.GridData2.DataBind();
ViewState["Dt"]=dt;
}
}