<asp:Button ID="Button1" runat="server" Text="添加货品信息" onclick="Button1_Click" />
<div runat="server" id="huopin"></div>/// <summary>
/// 添加货品信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button1_Click(object sender, EventArgs e)
{
HtmlTable mHmlTable = new HtmlTable(); Label lblhwType = null;
TextBox txthwType = null; HtmlTableRow HtmlRowhwType = new HtmlTableRow(); lblhwType = new Label();
lblhwType.Text = "货品类别:" ;
txthwType = new TextBox();
HtmlTableCell HtmlCellUserName = new HtmlTableCell();
HtmlCellUserName.Controls.Add(lblhwType);
HtmlRowhwType.Cells.Add(HtmlCellUserName);
HtmlTableCell HtmlCellUserCode = new HtmlTableCell();
HtmlCellUserCode.Controls.Add(txthwType);
HtmlRowhwType.Cells.Add(HtmlCellUserCode);
mHmlTable.Rows.Add(HtmlRowhwType); Label lblhwName = null;
TextBox txthwName = null; HtmlTableRow HtmlRowhwName = new HtmlTableRow(); lblhwName = new Label();
lblhwName.Text = "货品名:";
txthwName = new TextBox(); HtmlTableCell HtmlCelllblhwName = new HtmlTableCell();
HtmlCelllblhwName.Controls.Add(lblhwName);
HtmlRowhwName.Cells.Add(HtmlCelllblhwName); HtmlTableCell HtmlCelltxthwName = new HtmlTableCell();
HtmlCelltxthwName.Controls.Add(txthwName);
HtmlRowhwName.Cells.Add(HtmlCelltxthwName);
mHmlTable.Rows.Add(HtmlRowhwName);
huopin.Controls.Add(mHmlTable); }现在效果是第一次按钮,生成了一个表格,但是再点还是那一个。我想实现点一下就生成一个表格,不知该怎么处理,求助
<div runat="server" id="huopin"></div>/// <summary>
/// 添加货品信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button1_Click(object sender, EventArgs e)
{
HtmlTable mHmlTable = new HtmlTable(); Label lblhwType = null;
TextBox txthwType = null; HtmlTableRow HtmlRowhwType = new HtmlTableRow(); lblhwType = new Label();
lblhwType.Text = "货品类别:" ;
txthwType = new TextBox();
HtmlTableCell HtmlCellUserName = new HtmlTableCell();
HtmlCellUserName.Controls.Add(lblhwType);
HtmlRowhwType.Cells.Add(HtmlCellUserName);
HtmlTableCell HtmlCellUserCode = new HtmlTableCell();
HtmlCellUserCode.Controls.Add(txthwType);
HtmlRowhwType.Cells.Add(HtmlCellUserCode);
mHmlTable.Rows.Add(HtmlRowhwType); Label lblhwName = null;
TextBox txthwName = null; HtmlTableRow HtmlRowhwName = new HtmlTableRow(); lblhwName = new Label();
lblhwName.Text = "货品名:";
txthwName = new TextBox(); HtmlTableCell HtmlCelllblhwName = new HtmlTableCell();
HtmlCelllblhwName.Controls.Add(lblhwName);
HtmlRowhwName.Cells.Add(HtmlCelllblhwName); HtmlTableCell HtmlCelltxthwName = new HtmlTableCell();
HtmlCelltxthwName.Controls.Add(txthwName);
HtmlRowhwName.Cells.Add(HtmlCelltxthwName);
mHmlTable.Rows.Add(HtmlRowhwName);
huopin.Controls.Add(mHmlTable); }现在效果是第一次按钮,生成了一个表格,但是再点还是那一个。我想实现点一下就生成一个表格,不知该怎么处理,求助
{}
{
int count = 1;
if(ViewState["count"] != null)
{
count = Convert.ToInt32(ViewState["count"]);
if(count == 0)
{
count = 1;
}
for(int i = 0; i < count; ++i)
{
//生成控件代码
}
}
ViewState["count"] = ++count;
}
第一次就可出来了.当然要加在if(!isPostBack)里