如何在asp.net Webforms中以另一组动态替换一组服务器控件 [英] How to dynamically replace one set of server controls with another in asp.net webforms

查看:47
本文介绍了如何在asp.net Webforms中以另一组动态替换一组服务器控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理asp.net网络表单.我有一个用户控件,其中有几个服务器控件.有三个相关的下拉框.如果所有这些下拉框上都有多个值,则必须让用户从中选择值,然后将它们保存在数据库中.如果它们每个只有一个值,那么我必须将值显示为只读-例如asp.net标签.这些值也需要保存在数据库中.请让我知道如何将一组控件替换为另一组控件并获取它们的值.

I am working on asp.net webforms. I have a usercontrol which has several server controls. There are three related dropdown boxes. If there are multiple values on all these dropdown boxes, I have to let the user choose values from them and then I save them in database. If each one of them has only one value, then I have to show the values as read only - say as asp.net labels. These values also need to be saved in the database. Please let me know how to replace one set of controls with another and get their values.

谢谢

推荐答案

因此,要显示一组对另一组的控件,请考虑以下HTML:

So to show one set of controls over the other, consider the following HTML:

<asp:DropDownList ID="List1" runat="server" Visible="false" />
<asp:DropDownList ID="List2" runat="server" Visible="false" />
<asp:DropDownList ID="List3" runat="server" Visible="false" />
<asp:Label ID="Label1" runat="server" Visible="false" />
<asp:Label ID="Label2" runat="server" Visible="false" />
<asp:Label ID="Label3" runat="server" Visible="false" />

如果您希望下拉列表可见,请在相关代码后面的代码中运行此代码:

if you want the drop down lists visible then run this in the code-behind where relevant:

List1.Visible = true;
List2.Visible = true;
List3.Visible = true;

相反,如果您希望标签可见,请运行以下代码:

and in contrast, if you want the labels visible then run this code:

Label1.Visible = true;
Label2.Visible = true;
Label3.Visible = true;

请注意,当ASP.NET中的控件不可见可见时-会呈现.因此,该控件包含在HTML中.这就是为什么我将 所有它们 设置为不可见的原因.

Please note that when a control in ASP.NET is not visible - it's not rendered. So the control is not included in the HTML. This is why I set all of them to invisible to start with.

这篇关于如何在asp.net Webforms中以另一组动态替换一组服务器控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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