您如何根据用户在网络上的输入生成数据网格行,因此如果我在文本框中输入 5,则将生成 5 行,反之亦然。我已经在下面尝试了我的这段代码,但Exception of type 'System.OutOfMemoryException' was thrown每次我尝试运行我的程序时都会出错
我的 aspx.cs
private DataTable TempTable
{
get { return (DataTable)ViewState["TempTable"]; }
set { ViewState["TempTable"] = value; }
}
public void dtTemp()
{
TempTable = new DataTable();
TempTable.Columns.Add("ID_", typeof(string));
TempTable.Columns.Add("Name_", typeof(string));
TempTable.Columns.Add("Phone_", typeof(string));
}
protected void btnAdd_Click(object sender, ImageClickEventArgs e)
{
int rowTotal = Int32.Parse(totalRow.Text);
int i = 0;
panelTest.Visible = true;
dtTemp();
DataRow dr = TempTable.NewRow();
for (; ; )
{
if (i < rowTotal)
{
dr = TempTable.NewRow();
dr["ID_"] = "";
dr["Name_"] = "";
dr["Phone_"] = "";
TempTable.Rows.Add(dr);
grid1.DataSource = TempTable;
grid1.DataBind();
}
else
{
break;
}
}
}
相关分类