如何使下拉列表为空. [英] How to make drop down list empty.

查看:83
本文介绍了如何使下拉列表为空.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过为每个文本框,标签和下拉列表分配空值来制作刷新表单.下拉项目中有一个空的"项目.单击刷新按钮时如何分配它?

不要大喊大叫!使用所有大写字母被认为是在互联网上大喊大叫(所有小写字母都被认为是幼稚的.)不要做任何一个(而REALY则不要两者都做)-您只会惹恼别人. -OriginalGriff [/edit]

I am trying to make refresh form by assigning empty values to each textbox, labels, and drop down list. I have one empty " " item in drop down item. How do I assign it when refresh button is clicked?

DON''T SHOUT! Using all upper case is considered shouting on the internet (and all lower case is considered childish.) Don''t do either (and REALY don''t do both) - you will only annoy people. - OriginalGriff[/edit]

推荐答案

尝试:
myDropDownList.Items.Clear();


如果我答对了,您想将Web表单(标记为ASP.NET)中所有元素的值重置为空字符串.
如果这是您要查找的内容,则将页面发回不是一个好的解决方案.我建议您使用JavaScript进行此操作.
我举一个例子.

If I am got you correct, you want to reset the values of all the elements in your web form (tagged ASP.NET) to empty string.
If that is what you are looking for, posting back the page is not a good solution. I recommend you to use JavaScript to do this.
I will give you an example.

<div>
    <asp:TextBox ID="TextBox1" runat="server" MaxLength="30"></asp:TextBox>
    <asp:Label ID="Label1" runat="server" Text="" />
    <asp:DropDownList ID="DropDownList1" runat="server">
        <asp:ListItem></asp:ListItem>
        <asp:ListItem>Item 1</asp:ListItem>
        .
        .
    </asp:DropDownList>
    <asp:Button ID="btnReset" runat="server" Text="Reset" CausesValidation="False" OnClientClick="return clearControls();" UseSubmitBehavior="False" />
</div>


clearControls JavaScript函数


The clearControls JavaScript function

function clearControls()
        {
            document.getElementById('TextBox1').value = "";
            document.getElementById('Label1').innerHTML = "";
            document.getElementById('DropDownList1').selectedIndex = 0; //considering the empty string is at the 1st position
        }



希望这会有所帮助!

标签将是innerHTML而不是value.



Hope this helps!

It would be innerHTML instead of value for a label.


使用ComboBox.Items.Clear();


这篇关于如何使下拉列表为空.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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