为什么 点击Button会将 动态生成的DropDownList中不绑定的数据清空?
for (int i = 0; i < temp; ++i)
{
this.NewTableRow(i);
} protected void NewTableRow(int i)
{
TableRow tr = new TableRow();
TableCell tc;
TextBox tb;
Label td;
DropDownList tl; int rowqty = i + 1; tc = new TableCell();
td = new Label();
td.CssClass = "FieldStyle";
td.ID = "txtDel" + i;
td.Text = "" + rowqty;
tc.Controls.Add(td);
tr.Cells.Add(tc); tc = new TableCell();
tb = new TextBox();
tb.CssClass = "FieldStyle";
tb.ID = "txtItemno" + i;
tb.Attributes.Add("ondblclick", "getItem('" + i + "');");
tb.Attributes.Add("onclick", "getSelect('txtItemno"+ i + "');");
tc.Controls.Add(tb);
tr.Cells.Add(tc); tc = new TableCell();
tb = new TextBox();
tb.CssClass = "FieldStyle";
tb.TextMode = TextBoxMode.MultiLine;
tb.Rows = 2;
tb.ID = "txtDes" + i;
tb.Attributes.Add("onblur", "getfu('txtDes" + i + "');");
tc.Controls.Add(tb);
tr.Cells.Add(tc); tc = new TableCell();
tb = new TextBox();
tb.CssClass = "FieldStyle";
tb.ID = "txtModel" + i;
tb.Attributes.Add("onblur", "getfu('txtModel" + i + "');");
tc.Controls.Add(tb);
tr.Cells.Add(tc); tc = new TableCell();
tb = new TextBox();
tb.CssClass = "FieldStyle";
tb.ID = "txtQty" + i;
tb.Attributes.Add("onblur", "getsum('txtQty" + i + "');");
tb.Attributes.Add("onclick", "getSelect('txtQty" + i + "');");
tc.Controls.Add(tb);
tr.Cells.Add(tc); tc = new TableCell();
tb = new TextBox();
tb.CssClass = "FieldStyle";
tb.ID = "txtUOM" + i;
tc.Controls.Add(tb);
tr.Cells.Add(tc); tc = new TableCell();
tb = new TextBox();
tb.CssClass = "FieldStyle";
//tb.ReadOnly = true;
tb.ID = "txtDate" + i;
tb.Attributes.Add("onclick","SelectDate(this,'yyyy-MM-dd')");
tc.Controls.Add(tb);
tr.Cells.Add(tc); tc = new TableCell();
tb = new TextBox();
tb.CssClass = "FieldStyle";
tb.ID = "txtUPrice" + i;
tb.Attributes.Add("onblur", "getsum('txtUprice" + i + "');");
tb.Attributes.Add("onclick", "getSelect('txtUprice" + i + "');");
tc.Controls.Add(tb);
tr.Cells.Add(tc);
tc = new TableCell();
tb = new TextBox();
tb.CssClass = "FieldStyle";
tb.ID = "txtAccount" + i;
tc.Controls.Add(tb);
tr.Cells.Add(tc); tc = new TableCell();
tb = new TextBox();
tb.CssClass = "FieldStyle";
tb.ID = "txtQuote" + i;
tc.Controls.Add(tb);
tr.Cells.Add(tc); /*tc = new TableCell();
tb = new TextBox();
tb.CssClass = "FieldStyle";
tb.ID = "txtBuyer" + i;
tb.ReadOnly();
tc.Controls.Add(tb);
tr.Cells.Add(tc);*/ tc = new TableCell(); tl = new DropDownList();
tl.CssClass = "FieldStyle";
tl.ID = "txtBuyer" + i;
// tl.Style.Add("height", "21px");
for (int j = 0; j < tBuyer.Length; j++)
{
if (tBuyer[j]=="" | tBuyer[j]==null)
break;
tl.Items.Add(new ListItem(tBuyer[j],tBuyer[j]));
}
tr.Cells.Add(tc);
tc.Controls.Add(tl); //DropDownList("txtBuyer" + i).DataSource = tBuyer;
//DropDownList("txtBuyer" + i).DataBind();
// Enumerable.Range(1, 10).Select("txtBuyer" + i).ToList().ForEach(tl.Items.Add(i));
this.m_table.Rows.Add(tr); }
protected void btnAddDetail_Click(object sender, EventArgs e)
{
this.NewTableRow(this.Num++);
Label1.Text = this.Num.ToString();
}
for (int i = 0; i < temp; ++i)
{
this.NewTableRow(i);
} protected void NewTableRow(int i)
{
TableRow tr = new TableRow();
TableCell tc;
TextBox tb;
Label td;
DropDownList tl; int rowqty = i + 1; tc = new TableCell();
td = new Label();
td.CssClass = "FieldStyle";
td.ID = "txtDel" + i;
td.Text = "" + rowqty;
tc.Controls.Add(td);
tr.Cells.Add(tc); tc = new TableCell();
tb = new TextBox();
tb.CssClass = "FieldStyle";
tb.ID = "txtItemno" + i;
tb.Attributes.Add("ondblclick", "getItem('" + i + "');");
tb.Attributes.Add("onclick", "getSelect('txtItemno"+ i + "');");
tc.Controls.Add(tb);
tr.Cells.Add(tc); tc = new TableCell();
tb = new TextBox();
tb.CssClass = "FieldStyle";
tb.TextMode = TextBoxMode.MultiLine;
tb.Rows = 2;
tb.ID = "txtDes" + i;
tb.Attributes.Add("onblur", "getfu('txtDes" + i + "');");
tc.Controls.Add(tb);
tr.Cells.Add(tc); tc = new TableCell();
tb = new TextBox();
tb.CssClass = "FieldStyle";
tb.ID = "txtModel" + i;
tb.Attributes.Add("onblur", "getfu('txtModel" + i + "');");
tc.Controls.Add(tb);
tr.Cells.Add(tc); tc = new TableCell();
tb = new TextBox();
tb.CssClass = "FieldStyle";
tb.ID = "txtQty" + i;
tb.Attributes.Add("onblur", "getsum('txtQty" + i + "');");
tb.Attributes.Add("onclick", "getSelect('txtQty" + i + "');");
tc.Controls.Add(tb);
tr.Cells.Add(tc); tc = new TableCell();
tb = new TextBox();
tb.CssClass = "FieldStyle";
tb.ID = "txtUOM" + i;
tc.Controls.Add(tb);
tr.Cells.Add(tc); tc = new TableCell();
tb = new TextBox();
tb.CssClass = "FieldStyle";
//tb.ReadOnly = true;
tb.ID = "txtDate" + i;
tb.Attributes.Add("onclick","SelectDate(this,'yyyy-MM-dd')");
tc.Controls.Add(tb);
tr.Cells.Add(tc); tc = new TableCell();
tb = new TextBox();
tb.CssClass = "FieldStyle";
tb.ID = "txtUPrice" + i;
tb.Attributes.Add("onblur", "getsum('txtUprice" + i + "');");
tb.Attributes.Add("onclick", "getSelect('txtUprice" + i + "');");
tc.Controls.Add(tb);
tr.Cells.Add(tc);
tc = new TableCell();
tb = new TextBox();
tb.CssClass = "FieldStyle";
tb.ID = "txtAccount" + i;
tc.Controls.Add(tb);
tr.Cells.Add(tc); tc = new TableCell();
tb = new TextBox();
tb.CssClass = "FieldStyle";
tb.ID = "txtQuote" + i;
tc.Controls.Add(tb);
tr.Cells.Add(tc); /*tc = new TableCell();
tb = new TextBox();
tb.CssClass = "FieldStyle";
tb.ID = "txtBuyer" + i;
tb.ReadOnly();
tc.Controls.Add(tb);
tr.Cells.Add(tc);*/ tc = new TableCell(); tl = new DropDownList();
tl.CssClass = "FieldStyle";
tl.ID = "txtBuyer" + i;
// tl.Style.Add("height", "21px");
for (int j = 0; j < tBuyer.Length; j++)
{
if (tBuyer[j]=="" | tBuyer[j]==null)
break;
tl.Items.Add(new ListItem(tBuyer[j],tBuyer[j]));
}
tr.Cells.Add(tc);
tc.Controls.Add(tl); //DropDownList("txtBuyer" + i).DataSource = tBuyer;
//DropDownList("txtBuyer" + i).DataBind();
// Enumerable.Range(1, 10).Select("txtBuyer" + i).ToList().ForEach(tl.Items.Add(i));
this.m_table.Rows.Add(tr); }
protected void btnAddDetail_Click(object sender, EventArgs e)
{
this.NewTableRow(this.Num++);
Label1.Text = this.Num.ToString();
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货