如何在按钮点击上动态创建标签 [英] How to dynamically create labels on buttton click

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

问题描述

大家好,



我有一个带有一个下拉列表,一个文本框和一个按钮的表单。文本框基于下拉列表值填充。下拉列表中有许多值,对于每个值,我将在文本框中给出不同的值。



我需要的是当单击按钮时,下拉列表值和相应的文本框值应添加到标签或其他任何内容。因此,无论何时单击按钮,都应在表单下方动态添加两个值到新标签或任何不影响前一个标签的值添加标签。我怎么能这样做。因为我是C#的新手,我对它一无所知。任何帮助都会非常感激。谢谢。



我知道如何在gridview中做到这一点。但是这里的下拉列表值取自表格字段。因此下拉值会动态变化。



我尝试过:



我希望输出为:



Dropdownvalue Textboxvalue



1.Name ABC

2.Product XXX

3.Price 0.00

4.Unit 3

解决方案

您可以通过按钮的点击事件以编程方式将控件(在您的案例中为标签)添加到您的asp.net页面。



查看 MSDN文章,了解如何操作。



祝你有个美好的一天。


其实你可以使用< asp:literal>来做到这一点。控制。

Hi all,

I have a form with one dropdownlist,one textbox and one button . The textbox is filled based upon the dropdownlist value.There are many values in the dropdownlist and for each values i will give different values in the textbox.

What I need is that when the button is clicked the dropdownlist value and the corresponding textbox value should be added below to a label or anything.So whenever the button is clicked , both values should be added dynamically below the form to a new label or anything without affecting the previous added label .How can I do this .Since I am new to C# I don't have any idea about it.Any help will be really appreciated.Thanks in advance.

I know how to do it in gridview. But here the dropdownlist value is taken from a table field .So the dropdown values will change dynamically.

What I have tried:

I want the output as:

Dropdownvalue Textboxvalue

1.Name ABC
2.Product XXX
3.Price 0.00
4.Unit 3

解决方案

You can programmatically add the controls(labels in your case) to your asp.net page on the click event of your button.

Take a look at this MSDN article to know how to do it.

Have a good day.


Actually you can be do this by using <asp:literal> control.


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

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