0

我有 3 个更新面板控件 asp.net,其中updatePanel1, updatePanel2, updatePanel3. 首次加载页面时updatePanel1会自动加载更多buttonsex: button1. 单击button1updatePanel1,将显示updatePanel2ex:中的按钮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>
4

1 回答 1

1

这与视图状态有关。由于 updatepanel2 中的按钮是在运行时创建的,因此它们会在 page_load 事件中丢失。每次都必须重新生成。您将如何实现它取决于您如何编写代码。没有代码我不能告诉你更多。

于 2013-06-07T08:59:15.707 回答