按钮上的动态列表点击 [英] Dynamic List on Button Click

查看:81
本文介绍了按钮上的动态列表点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个文本框和两个按钮(添加和显示).
我希望当我在文本框中输入值后单击添加按钮时,该值应添加到显示按钮单击中将出现的列表中.

请指导我如何处理.
在此先感谢

Hi,

I have a textbox and two buttons (Add and Show).
I want that when I click on add button after entering a value in the textbox then that value should be added in list which would appear on Show button click.

Please guide me how I can handle this.
Thanks in Advance

推荐答案

添加文本框
为添加"按钮添加事件处理程序,从文本框中检索文本,存储在db
为显示按钮添加事件处理程序,从数据库中选择列表,渲染列表

更新:
如果您拥有相同的按钮以同时充当添加"和显示"按钮:
为添加/显示"按钮添加事件处理程序-如果文本为添加",则从按钮检索文本;执行文本;如果文本为显示",则执行显示功能.对于其余部分,请执行上述操作.

问候
Espen Harlinn
add textbox
add eventhandler for Add button, retrieve text from textbox, store in db
add eventhandler for Show button, select list from db, render list

Update:
If you wnat the same button to act as both an Add and a show button:
add eventhandler for Add/Show button - retrieve text from button if text is "Add" execute add functionality, if text is "Show" execute show functionality. For the rest do as above.

Regards
Espen Harlinn


尝试以下代码:
Try this code:
private ICollection<string> lst = new List<string>();
        private void btnAdd_Click(object sender, EventArgs e)
        {
            lst.Add(txtValue.Text);
        }
        private void btnShow_Click(object sender, EventArgs e)
        {
            listBox1.DataSource = lst;
            listBox1.DataBind();
        }



这里的变化很小,第二个按钮是显示/隐藏".它不仅应显示列表,而且当我再次单击它时,列表也应消失.我可以通过Ajax实现此功能吗?
Hi,
There is little change here the second button is Show/Hide. It should not only show the list but when i click it again the list should disappear. Can i achieve this functionality through ajax?


这篇关于按钮上的动态列表点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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