我想动态让行,其中存在的所有沿,但在第一隐藏可见。
我已经尝试了客户端(jQuery的)路线,但曾与该问题。
我宁愿下去服务器端(C#)的道路,我想我已经找到了它的基础上完成的方式这个主题和下面的代码:
HtmlButton btnAddFoapalRow = null;
. . .
btnAddFoapalRow = new HtmlButton();
btnAddFoapalRow.Attributes["type"] = "button";
btnAddFoapalRow.InnerHtml = "+";
btnAddFoapalRow.ID = "btnAddFoapalRow";
btnAddFoapalRow.ServerClick += new EventHandler(btnAddFoapalRow_Click);
this.Controls.Add(btnAddFoapalRow);
private void btnAddFoapalRow_Click(object sender, EventArgs e)
{
try
{
ShowNextFoapalRow();
}
catch (Exception ex)
{
String s = String.Format("Exception occurred: {0}", ex.Message); // TODO: Log this somewhere
}
}
//// This only works the first time, because it causes the page to be reloaded, setting foapalRowsShowing back to 2
private void ShowNextFoapalRow()
{
switch (foapalRowsShowing)
{
case 2:
foapalrow3.Visible = true;
foapalRowsShowing = 3;
break;
case 3:
foapalrow4.Visible = true;
foapalRowsShowing = 4;
btnAddFoapalRow.Disabled = true;
break;
}
}
foapalrow3 = new HtmlTableRow();
foapalrow3.ID = "foapalrow3";
foapalrow3.Visible = false;
. . .
foapalrow3 = new HtmlTableRow();
foapalrow3.ID = "foapalrow3";
foapalrow3.Visible = false;
......但没有去 - 在第一时间第二行是可见,但“+” HtmlButton的后续糖化不会使第三排可见。 并加强通过代码,我明白为什么:在页面的每个我捣碎按钮时提交,ADN因此初始代码再次运行,设置行可见的回数为两个,并始终使ROW3可见(从未ROW4)。
这是什么样子捣碎的按钮,无论多少次,我捣碎按钮后(多一个排应补充,但它永远不会是):
行1,顺便说一句,是列标题行; 行2是单列即默认可见; ROW3和ROW4存在,但不可见在第一。