我需要通过单击按钮生成动态图像并将其拖动到面板中。
我将添加图像的面板也可以通过单击按钮动态创建。问题是如果我单击另一个按钮说添加图像(用于动态添加图像),添加的面板将被隐藏。如果我再次单击添加面板按钮,我可以看到以前添加的面板 + 新面板。
这是因为回帖还是什么?
这是我的 C# 代码:
private void addRow1()
{
for (int i = 0; i < row_cnt; i++)
{
var row = new TableRow();
var cell = new TableCell();
var tbl = new Table();
cell.Height = Unit.Pixel(100);
cell.Width = Unit.Percentage(100);
var pnl1 = new Panel();
pnl1.ID = "Panel" + i;
pnl1.Width = Unit.Percentage(800);
pnl1.Height = Unit.Percentage(100);
pnl1.BackColor = Color.FromArgb(255, 231, 229, 246);
pnl1.Visible = true;
pnl1.BorderStyle = BorderStyle.Solid;
pnl1.BorderWidth = Unit.Pixel(2);
cell.Controls.Add(pnl1);
row.Cells.Add(cell);
TableMain.Rows.Add(row);
pnl1.Controls.Add(tbl);
tbl.ID = "tbl" + (i + 1);
tbl.BorderStyle = BorderStyle.Solid;
tbl.Width = Unit.Percentage(100);
tbl.BorderWidth = Unit.Pixel(1);
var tbl_row = new TableRow();
var tbl_cell = new TableCell();
tbl_cell.Height = Unit.Pixel(90);
tbl_cell.Width = Unit.Pixel(20);
tbl_cell.BorderStyle = BorderStyle.Solid;
tbl_cell.BorderWidth = Unit.Pixel(2);
tbl_row.Cells.Add(tbl_cell);
tbl.Rows.Add(tbl_row);
}
}
这是HTML:
<body>
<form id="form1" runat="server">
<div id="div" runat="server" style="width: 1000px; height: 500px; background-color:lightgoldenrodyellow ">
<asp:Button ID="Button1" runat="server" Text="ADD SLAB" OnClick="Button1Click" />
<asp:Button ID="Button2" runat="server" Text="ADD IMAGE" OnClick="Button2Click" />
<asp:Table ID="TableMain" runat="server" Border="0">
</asp:Table>
</div>
</form>
</body>