如何在运行时用另一个控件替换一个控件 [英] how to replace a control with another control in run time

查看:70
本文介绍了如何在运行时用另一个控件替换一个控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


谁能在运行时帮助我替换另一个控件(例如用单选按钮替换组合框).


Can anyone help me in replacing a control with another (like replacing combobox with radio button) in runtime.

推荐答案

是的,但是可以在以下两种情况下进行:
首先,控件必须存在于父控件(如parent)中!
其次,您应该拥有他们的ID!
yes you can but in 2 condition:
first, the controls have to exists in a parent control like parent!
second, you should have their ID!
protected void Page_Load(object sender, EventArgs e)
        {
            Panel1.Controls.Remove(Button1);
            RadioButton rdbtn = new RadioButton();
            rdbtn.Checked = false;
            rdbtn.ID = "rdbtn";
            rdbtn.Text = "your aswer?";
            Panel1.Controls.Add(rdbtn);
        }


解释我的代码:
我在面板控件中有一个按钮,在page_load方法中,我删除了button,并且
制作一个新的复选框控件,并将其设置为这些值,然后将此控件添加到面板中!


explain of my code:
I have a button in a panel control, and in page_load method i remove button , and
make a new checkbox control , and set it to these values and add this control to panel!


这篇关于如何在运行时用另一个控件替换一个控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆