Modalpopupextender不工作

时间:2013-08-31 14:23:20

标签: c# asp.net ajaxcontroltoolkit modalpopupextender

我正在尝试在modalpopup extnder中创建一个gridview。但是一旦我点击触发事件的按钮来创建它,它似乎就像一个链接到另一个页面而不是弹出一个窗口。以下是我的代码:

protected void Page_Load(object sender, EventArgs e)
    {
        DataTable table = GetTable();
        GridView gv = new GridView();
        gv.ID = "GridView1";
        gv.DataSource = table;
        gv.DataBind();

        Button btn = new Button();
        btn.ID = "button1";
        btn.Click += (sender, e) => CreateModalPop(ph, btn.ID);

        DynamicControlsHolder1.Controls.Add(gv);
        DynamicControlsHolder1.Controls.Add(btn);
    }


static DataTable GetTable()
    {
        //
        // Here we create a DataTable with four columns.
        //
        DataTable table = new DataTable();
        table.Columns.Add("Dosage", typeof(int));
        table.Columns.Add("Drug", typeof(string));
        table.Columns.Add("Patient", typeof(string));
        table.Columns.Add("Date", typeof(DateTime));

        //
        // Here we add five DataRows.
        //
        table.Rows.Add(25, "Indocin", "David", DateTime.Now);
        table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now);
        table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now);
        table.Rows.Add(21, "Combivent", "Janet", DateTime.Now);
        table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);
        return table;
    }


    protected void CreateModalPop(PlaceHolder ph, string btnID)
    {

        DataTable tableNew = GetTable();

        GridView gv = new GridView();
        gv.ID = "GridViewNew1"
        gv.AutoGenerateColumns = true;
        gv.DataSource = tableNew;
        gv.DataBind();


        Panel pn = new Panel();
        pn.ID = "Panel1";
        pn.Controls.Add(gv);


        AjaxControlToolkit.ModalPopupExtender modalPop = new AjaxControlToolkit.ModalPopupExtender();
        modalPop.ID = "ModalPopup-1";
        modalPop.PopupControlID = "Panel1"
        modalPop.TargetControlID = btnID; 
        modalPop.X = 50;
        modalPop.Y = 50;
        modalPop.Show();

        // Adding modalpop to panel
        pn.Controls.Add(modalPop);

        // Adding Panel to placeholder
        ph.Controls.Add(pn);

    }

0 个答案:

没有答案