List<Column> colList = new List<Column>(); ColumnManager cm = new ColumnManager(); string dbname = null;protected void Button5_Click(object sender, EventArgs e)
{
if (colList == null)
{
colList = new List<Column>();
} int count = 0; for (int i = 0; i < this.ListBox2.Items.Count; i++)
{
if (this.txtColName.Text.Trim().Equals(this.ListBox2.Items[i].Text))
{
count++;
}
} if (count == 0)
{
Column column = new Column();
column.Name = this.txtColName.Text;
column.DbType = this.DropDownList1.Text.ToString();
this.ListBox2.Items.Add(column.Name);
colList.Add(column);
}
else
{
Response.Write("<script language='javascript' type='text/javascript'>alert('此表已包含此字段')</script>");
}
}protected void Button4_Click(object sender, EventArgs e)
{
IList<Column> all = new List<Column>();
。 if (colList.Count > 0)
{
for (int i = 0; i < colList.Count; i++)
{
all.Add(colList[i]);
}
} string sql = "USE " + dbname + " " +
"GO " +
"CREATE TABLE " + tablename + " " +
"( ";
for (int i = 0; i < all.Count; i++)
{
Column column=(Column)all[i];
sql += column.Name + " " + column.DbType+", ";
}
sql = sql.Substring(0, sql.Length - 2) + " )";
}
问题是:Button5的Click事件触发后colList有值,再触发Button4的Click事件时colList就没值了;
我试过让colList在Button5的Click的事件里面实例化,但是还是就没有效果
点击Button4 要实例化一次 所以是空的
{
colList = new List<Column>();
}然后
Button4中判断
if (colList == null)
{
colList = new List<Column>();
}
List<Column> colList = new List<Column>();你点击button4的时候,页面重新加载,上面这句话执行,然后button5不执行
等于你只是对colList进行了实例,所以为NULL