我有 3 个更新面板控件 asp.net,其中updatePanel1
, updatePanel2
, updatePanel3
. 首次加载页面时updatePanel1
会自动加载更多buttons
ex: button1
. 单击button1
时updatePanel1
,将显示updatePanel2
ex:中的按钮button2
。单击button2
时,它将触发并以类似gridview的形式updatePanel3
显示数据。updatePanel3
现在,我的问题是单击丢失button2
的所有按钮时。updatePanel2
你能给我解决为什么我失去按钮updatePanel2
吗?
UPDATE
Default.cs
protected void Page_Load(object sender, EventArgs e) { foreach (KeyValuePair<String, String> catshow in cat) { Button x = new Button(); x.ID = catshow.Key; x.CssClass = "btnTop"; x.Text = catshow.Value; x.CommandArgument = catshow.Key; x.Command += new CommandEventHandler(buttonClick); PlaceHolder1.Controls.Add(x); } } protected void buttonClick(object sender, CommandEventArgs e) { string key = e.CommandArgument.ToString(); foreach (KeyValuePair<String, String> datshow in data[key]) { Button x = new Button(); x.ID = datshow.Key; x.CssClass = "btnBottom"; x.Text = datshow.Value; x.CommandArgument = datshow.Key; x.Command += new CommandEventHandler(buttonClickPrd); PlaceHolder2.Controls.Add(x); } } protected void buttonClickPrd(object sender, CommandEventArgs e) { string key = e.CommandArgument.ToString(); DataTable dt = new DataTable(); dt.Columns.Add("Qty", Type.GetType("System.String")); dt.Columns.Add("Unit", Type.GetType("System.String")); dt.Columns.Add("Price", Type.GetType("System.String")); dt.Columns.Add("Total", Type.GetType("System.String")); dt.Rows.Add(); dt.Rows[dt.Rows.Count - 1]["Qty"] = this.sales[key]["qty"]; dt.Rows[dt.Rows.Count - 1]["Unit"] = this.sales[key]["unit"]; dt.Rows[dt.Rows.Count - 1]["Price"] = this.sales[key]["price"]; dt.Rows[dt.Rows.Count - 1]["Total"] = this.sales[key]["total"]; GridView1.DataSource = dt; GridView1.DataBind(); }
Default.aspx
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:PlaceHolder ID="PlaceHolder2" runat="server"></asp:PlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>