我正在尝试根据从下拉列表中选择的金额显示一组文本框。假设我选择5然后它应该显示5个文本框;然而,在页面加载时会显示文本框,它会清除框。另外我想输入输入数据库表的那些数据。
protected void ddlCount_SelectedIndexChanged(object sender, EventArgs e)
{
ContentPlaceHolder1.Controls.Clear();
for (int i = 0; i < Convert.ToInt32(ddlCount.SelectedItem.Value); i++)
{
TextBox tx = new TextBox();
tx.ID = "tx" + i;
ContentPlaceHolder1.Controls.Add(tx);
ContentPlaceHolder1.Controls.Add(new LiteralControl(" "));
}
}
按钮单击
protected void btnPrint_Click(object sender, EventArgs e)
foreach (Control ctrl in ContentPlaceHolder1.Controls)
{
SqlCommand comm = new SqlCommand();
{
Label ll = (Label)ContentPlaceHolder1.FindControl("Label5");
comm.CommandType = CommandType.StoredProcedure;
comm.CommandText = "PP_CreateUserNumber";
comm.Connection = con;
comm.Parameters.Add("@sealNumber", SqlDbType.NVarChar).Value = 11;
comm.ExecuteNonQuery();
}
}
}