为什么 点击Button会将 动态生成的DropDownList中不绑定的数据清空?

M057612 M057612 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
为什么 点击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();

}
...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
M057612
.NET社区 62,273 成员 668,968 内容