如何将控件放在动态表中

时间:2019-01-16 11:05:38

标签: c# asp.net telerik

我正在创建按钮的动态控件onclick,并且具有radwizardsteps,它们也是动态生成的。每个向导步骤都会在其中创建一个动态表。

我想将动态生成的控件放入此Wizardstep表中。由于表格是动态的,所以我无法找到如何访问表格,请有人帮我实现。

谢谢。

dynamicTable Table;

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        GenerateWizardSteps(3);
        RadListView1.DataSource = GetDatatable();
        RadListView1.DataBind();
    }
}

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

    try
    {
        for (int i = 0; i < formID; i++)
        {
            step = new RadWizardStep();
            step.ClientIDMode = ClientIDMode.Static;
            step.ID = "step_" + i;
            step.CssClass = "Table";
            step.Title = "step_" + i;
            dynamicTable = new Table();
            dynamicTable.ClientIDMode = ClientIDMode.Static;
            dynamicTable.ID = "controlTable_" + i;
            dynamicTable.Attributes.Add("style", "border:1px solid");
            step.Controls.Add(dynamicTable);
            UiControlsWizard.WizardSteps.Add(step);
        }
    }
}

// Dynamic Controls Creation
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);
            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);
                        Table1.Rows.Add(txtRow);
                    }
                }
            }
        }
    }
}

在这里,我将控件放在名为 Table1 的静态表中。我想将相同的控件放入动态表中。

0 个答案:

没有答案