导航时如何在运行时删除控件



我将为候选人创建在线测试。我有以下要求:

当我按下下一个按钮控件(例如(问题编号(,问题文本,带有文本的无线电按钮的标签时(,然后按下Next Next按钮时,我想要下一个记录,但是在示例的地方,第一个问题是所有控件。这怎么可能?如果是,请帮助我。这是我尝试过的代码。 DT是我已经填充的数据

 protected void btnPrev_Click(object sender, EventArgs e)
    {
        if (increment > 0)
        {
            increment--;
            NavigateRecords();
        }                //tbFirst.Text = increment.ToString();
        else
        {
            //MessageBox.Show("First Record");
        }
    }

protected void btnLast_Click(object sender, EventArgs e)
    {
        maxRows = dt.Rows.Count;
        if (increment != maxRows - 1)
        {
            // tbFirst.Text = increment.ToString();
            increment = maxRows - 1;
            NavigateRecords();
        }
    }                

protected void btnFirst_Click(object sender, EventArgs e)
    {
        if (increment > 0)
        {
            increment = 0;
            NavigateRecords();
        }                //tbFirst.Text = increment.ToString();
}

    protected void btnNext_Click(object sender, EventArgs e)          
    {
        maxRows = dt.Rows.Count;
        if (increment != maxRows - 1)
        {
            increment++;
            NavigateRecords();
        }
        else
        {
        }
    }
    public void NavigateRecords()
    {
        Page.Controls.Clear();
        dr = dt.Rows[increment];
        Label[] questionNo = new Label[dt.Rows.Count];
        Label[] questionText = new Label[dt.Rows.Count];
        RadioButton[] rbs = new RadioButton[dt.Rows.Count];
            //question no
            questionNo[increment] = new Label();
            questionNo[increment].Text = "<h3><div class="center-
           block">Question: " + dt.Rows[increment]["SrNo"].ToString() + "</div></h3>";
            //question text
            questionText[increment] = new Label();
            questionText[increment].Text = "<h3>" + dt.Rows[increment]["QuestionText"].ToString() + "</h3>";
            divQuestionText.Controls.Add(questionNo[increment]);
            divQuestionText.Controls.Add(questionText[increment]);
            for (j = 3; j <= 6; j++)
            {
                rbs[increment] = new RadioButton();
                //option
                rbs[increment].GroupName = increment.ToString();
                rbs[increment].Text = dt.Rows[increment][j].ToString() + "<br>";
                divQuestionText.Controls.Add(rbs[increment]);
            }
        }

最简单的方法是为您所拥有的每个步骤创建自己的Panel。然后,在btnNext_Click-事件上,您必须在后台推动面板或使用Control.Visible属性使其失败,然后将下一个属性带到前面。

这样,您就拥有" VS Form Inspector"所需的所有控件,而不必弄乱代码中的控制位置。

MFG

bms

最新更新