如何将RadControls添加到动态创建的表

时间:2019-01-22 13:46:11

标签: c# asp.net telerik

我创建了由(文本框,ddl,组合框等)组成的rad动态控件,还创建了动态rad向导步骤,每个向导步骤都包含一个动态表。

我想将这些动态rad控件插入Wizardstep表中,以实现我使用的会话,但是它给出了一个例外,表示在PreRender之后可能未注册脚本控件。

当我尝试将这些控件插入静态asp表中时,它工作正常,而添加到动态表中却遇到了这个问题。我做错了什么,我该如何解决这个问题。

请指导我,我是编程新手。

后面的代码:

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GenerateWizardSteps(2);
            RadListView1.DataSource = GetDatatable();
            RadListView1.DataBind();
        }
        else
        {
            RecreateControls("rtb", "RadTextBox");
        }
    }
    public DataTable GetDatatable()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("Label");

        dt.Rows.Add("RadTextBox");
        return dt;
    }

    //Creating WizardSteps
    public void GenerateWizardSteps(int formID)
    {
        RadWizardStep step;

        step = new RadWizardStep();
        step.ClientIDMode = ClientIDMode.Static;
        step.ID = "step_" + i.ToString();
        controlTbl = new Table();
        controlTbl.ClientIDMode = ClientIDMode.Static;
        controlTbl.ID = "controlTable_" + i.ToString();
        Session["myTable"] = controlTbl;
        step.Controls.Add(controlTbl);
        wizardControl.WizardSteps.Add(step);
     }
 protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e)
    {
        string commandText = e.Argument.ToString().Trim();
        string[] splitdata = commandText.Split('&');
        commandText = splitdata[0];
        string controlName = splitdata[1];
        switch (controlName)
        {
            case "RadTextBox":
                int cnt1 = FindOccurence("rtb") + 1;
                DynamicControls dcTextBox = new DynamicControls();
                TableCell txtlblRad = dcTextBox.Controlscreation("RadLabel", "", cnt1, cnt1, "Text Box:", "", 0);
                TableCell txtRad = dcTextBox.Controlscreation("RadTextBox", "", cnt1, cnt1, "", "", 0);
                TableRow txtRow = new TableRow();
                txtRow.Cells.Add(txtlblRad);
                txtRow.Cells.Add(txtRad);
                Table controlTbl = Session["myTable"] as Table;
                controlTbl.Rows.Add(txtRow);
                //Table1.Rows.Add(txtRow);

                break;
         }
    }
    private void RecreateControls(string ctrlPrefix, string ctrlType)
    {
        string[] ctrls = Request.Form.ToString().Split('&');
        int cnt = FindOccurence(ctrlPrefix);
        if (cnt > 0)
        {
            for (int k = 1; k <= cnt; k++)
            {
                for (int i = 0; i < ctrls.Length; i++)
                {
                    if (ctrls[i].Contains(ctrlPrefix + "_" + k.ToString()))
                    {

                        if (ctrlType == "RadTextBox")
                        {
                            DynamicControls dcTextBox = new DynamicControls();
                            TableCell txtlblRad = dcTextBox.Controlscreation("RadLabel", "", k, k, "TextBox:", "", 0);
                            TableCell txtRad = dcTextBox.Controlscreation("RadTextBox", "", k, k, "", "", 0);
                            TableRow txtRow = new TableRow();
                            txtRow.Cells.Add(txtlblRad);
                            txtRow.Cells.Add(txtRad);
                            Table controlTbl = Session["myTable"] as Table;
                            controlTbl.Rows.Add(txtRow);
                        }
                           break;
                    }
                }
            }
        }
    }

    private int FindOccurence(string substr)
    {
        string reqstr = Request.Form.ToString();
        //return (((reqstr.Length - reqstr.Replace(substr, "").Length) / substr.Length) / 2);
        return ((reqstr.Length - reqstr.Replace(substr, "").Length) / substr.Length);
    }

0 个答案:

没有答案